Android:Cardview背景在4.1.2上变为黑色 [英] Android : Cardview Background is turning to black on 4.1.2
问题描述
我正在使用google cardView支持库来实现我的卡功能.它适用于kitkat和版本升级,但卡的背景设置为黑色,并且在设备4.1.2上未应用填充/边距.
I am using google cardView support library for my card functionality. It works well for kitkat and version up but however the background of card is set to black and padding/margins are not applied on device 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>
推荐答案
好吧,我偶然发现了同一个问题,发现某些设备具有特殊的"非常轻的,以咳嗽为主题的默认设置咳嗽三星咳嗽我会回答这个有点老的问题.
Okay, I just stumbled across the same issue and I found some devices to have some "special" very-light light-theming defaults cough samsung cough I will answer this slightly old queston.
这里的事情是,您很可能使用了错误的context
来夸大您的布局.我认为您正在使用application-context
来执行此操作. Application-Context不应用您定义的主题.
The thing here is that you are most likely using the wrong context
to inflate you layout. I think you are using the application-context
to do so. Application-Context does not apply the theme you defined.
此(在应用程序上下文中夸大)是合法的,但会导致通货膨胀 将使用您所在系统的默认主题来完成 正在运行,而不是您的应用程序中定义的内容.*
This (inflating with the application-context) is legal, but inflation will be done with the default theme for the system on which you are running, not what’s defined in your application.*
例如,如果您这样做:
LayoutInflater.from(context).inflate(R.layout.menu_rental_list_item, parent, false);
此处的context
应该是Activity-
或Fragment
Context
-而不是应用程序上下文.
The context
here should be an Activity-
or Fragment
Context
- NOT the application-context.
请仔细检查.
*)啊,您想了解更多有关上下文的信息吗?请继续在此处阅读.
*) Ah, you want to read more about contexts? Please continue reading here.
这篇关于Android:Cardview背景在4.1.2上变为黑色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!