CardView에서 투명한 배경을 만들고 싶습니다. backgroundColor를 알고 있지만 레이아웃에 이미지가 있습니다.
어떻게하는지 아십니까? 아니면 cardview로 작동하지만 투명한 배경을 설정할 것입니까?
문안 인사
CardView에서 투명한 배경을 만들고 싶습니다. backgroundColor를 알고 있지만 레이아웃에 이미지가 있습니다.
어떻게하는지 아십니까? 아니면 cardview로 작동하지만 투명한 배경을 설정할 것입니까?
문안 인사
답변:
cardBackgroundColor속성 을 사용하여 색 cardElevation을 제거하고 그림자를 제거하는 속성 을 사용하도록 CardView를 설정하십시오 . 예를 들면 :
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/myCardView"
android:layout_width="match_parent"
android:layout_height="match_parent"
card_view:cardBackgroundColor="@android:color/transparent"
card_view:cardElevation="0dp">
지원되는 속성의 전체 목록은 https://developer.android.com/reference/android/support/v7/widget/CardView.html을 참조하십시오.
이전 API를 사용하는 경우 CardView대신 다음 두 함수를 호출해야 합니다.
myCardView.setCardBackgroundColor(Color.TRANSPARENT);
myCardView.setCardElevation(0);
setCardElevation()및 setCardBackgroundColor()귀하의 코드에서 CardView내 편집 을 참조하십시오.
@null작동하지 않았습니다.
Android를 CardView투명하게 만드는 간단한 2 단계 .
설정합니다 app:cardBackgroundColor="@android:color/transparent". 이다 CardView세트 배경 속성.
app:cardElevation="0dp"그림자를 제거하도록 설정 합니다.
예를 들어, 다음은 투명하게 만드는 작은 xml 코드입니다. CardView
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/card_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:cardBackgroundColor="@android:color/transparent"
app:cardElevation="0dp" />
Note: Don't use
. UsesetBackgroundapp:cardBackgroundColorinstead.
In my case, I used the attribute android:backgroundTint="@color/some_color",it is only used en API level 21 and higher. And color #50000000 for example.
<android.support.v7.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
card_view:cardCornerRadius="3dp"
app:cardElevation="0dp"
android:backgroundTint="@color/negro_label"
>
This should work on API 17
cardView.setBackgroundColor(ContextCompat.getColor(getContext(), android.R.color.transparent));
use app:cardBackgroundColor="@android:color/transparent"
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="20dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="10dp"
app:cardCornerRadius="16dp"
app:cardElevation="16dp"
app:cardBackgroundColor="@android:color/transparent" >
<--inside cardlayout-->
</android.support.v7.widget.CardView>
android:background="@android:color/transparent"