且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Android:Cardview背景在4.1.2上变为黑色

更新时间:2023-10-31 23:16:58

好吧,我偶然发现了同一个问题,发现某些设备具有特殊的"非常轻的,以咳嗽为主题的默认设置咳嗽三星咳嗽我会回答这个有点老的问题.

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.