Android:Cardview Background在4.1.2上变为黑色

Sut*_*rth 14 user-interface android android-layout

我正在使用谷歌cardView支持库来获取我的卡功能.它适用于kitkat和版本,但卡的背景设置为黑色,填充/边距不适用于设备4.1.2.

<android.support.v7.widget.CardView
        android:id="@+id/all_goals_card_view"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:layout_marginRight="20dp"
        android:layout_marginLeft="20dp"
        android:layout_gravity="center"
        android:layout_marginTop="20dp"
        android:layout_marginBottom="20dp"
        android:padding="10dp"
        app:cardCornerRadius="4dp"
        card_view:cardPreventCornerOverlap="false"
        card_view:cardBackgroundColor="@android:color/white"
        >
 </android.support.v7.widget.CardView>
Run Code Online (Sandbox Code Playgroud)

Lan*_*tel 39

好吧,我偶然发现了同样的问题,我发现一些设备有一些"特殊的"非常轻的光线 - 默认咳嗽三星咳嗽我会回答这个稍微陈旧的问题.

这里的事情是你最有可能使用错误context来夸大你的布局.我认为你正在使用application-context这样做.Application-Context不适用您定义的主题.

(充满应用程序上下文)是合法的,但通货膨胀将使用您运行的系统的默认主题完成,而不是在您的应用程序中定义的内容.*

例如,如果你这样做:

LayoutInflater.from(context).inflate(R.layout.menu_rental_list_item, parent, false);
Run Code Online (Sandbox Code Playgroud)

context这里应该是一个Activity-Fragment Context-而不是应用程序上下文.

请仔细检查一下.

*)啊,你想了解更多有关上下文的内容吗?请继续在这里阅读.


小智 7

不要使用"@android:color/white"

card_view:cardBackgroundColor="#fff"
Run Code Online (Sandbox Code Playgroud)

  • 使用`app:cardBackgroundColor ="#fff"`.但是谢谢. (4认同)