android,如何在使用Theme.AppCompat.Light.DarkActionBar时使用MaterialCardView
该应用程序将androidX与minSdk 21配合使用,并使用android,如何在使用Theme.AppCompat.Light.DarkActionBar时使用MaterialCardView,android,android-night-mode,materialcardview,Android,Android Night Mode,Materialcardview,该应用程序将androidX与minSdk 21配合使用,并使用 AppCompatActivity主题: <style name="myAppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> <item name="colorPrimary">@color/theme_colorPrimary</item> <item name="colorPrimaryDark"
AppCompatActivity
主题:
<style name="myAppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">@color/theme_colorPrimary</item>
<item name="colorPrimaryDark">@color/theme_colorPrimaryDark</item>
<item name="colorAccent">@color/theme_colorAccent</item>
</style>
但是当使用com.google.android.material.card.MaterialCardView
(使用实现'com.google.android.material:material:1.1.0'
)
原因可能是什么?
如果使用MaterialCardView,应该使用什么主题,并且仍然能够执行
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES)
注:
在,
它表示将应用程序主题更改为继承自材质组件主题
,以及
Material Components themes
The following is the list of Material Components themes you can use to get the latest component styles and theme-level attributes.
Theme.MaterialComponents
Theme.MaterialComponents.NoActionBar
Theme.MaterialComponents.Light
Theme.MaterialComponents.Light.NoActionBar
Theme.MaterialComponents.Light.DarkActionBar
Theme.MaterialComponents.DayNight
Theme.MaterialComponents.DayNight.NoActionBar
Theme.MaterialComponents.DayNight.DarkActionBar
Update your app theme to inherit from one of these themes, e.g.:
<style name="Theme.MyApp" parent="Theme.MaterialComponents.DayNight">
<!-- ... -->
</style>
而
Theme.MaterialComponents.Light.DarkActionBar
从android:Theme.Material.Light.NoActionBar
尝试在MaterialCardView中使用它吗
<style name="Theme.AppCompat.Light.DarkActionBar" parent="Base.Theme.AppCompat.Light.DarkActionBar"/>
<style name="Base.Theme.AppCompat.Light.DarkActionBar" parent="Base.Theme.AppCompat.Light">
<style name="Base.Theme.AppCompat.Light" parent="Base.V21.Theme.AppCompat.Light"/>
<style name="Base.V21.Theme.AppCompat.Light" parent="Base.V7.Theme.AppCompat.Light">
<style name="Base.V7.Theme.AppCompat.Light" parent="Platform.AppCompat.Light">
<style name="Platform.AppCompat.Light" parent="Platform.V21.AppCompat.Light"/>
<style name="Platform.V21.AppCompat.Light" parent="android:Theme.Material.Light.NoActionBar">
android:theme="@style/Theme.MaterialComponents.DayNight.DarkActionBar"
我相信,在MaterialCardView中添加此内容不会影响应用程序主题。您必须使用主题。MaterialComponents.*主题可能会帮助您解决问题
Material Components themes
The following is the list of Material Components themes you can use to get the latest component styles and theme-level attributes.
Theme.MaterialComponents
Theme.MaterialComponents.NoActionBar
Theme.MaterialComponents.Light
Theme.MaterialComponents.Light.NoActionBar
Theme.MaterialComponents.Light.DarkActionBar
Theme.MaterialComponents.DayNight
Theme.MaterialComponents.DayNight.NoActionBar
Theme.MaterialComponents.DayNight.DarkActionBar
Update your app theme to inherit from one of these themes, e.g.:
<style name="Theme.MyApp" parent="Theme.MaterialComponents.DayNight">
<!-- ... -->
</style>
<style name="Theme.AppCompat.Light.DarkActionBar" parent="Base.Theme.AppCompat.Light.DarkActionBar"/>
<style name="Base.Theme.AppCompat.Light.DarkActionBar" parent="Base.Theme.AppCompat.Light">
<style name="Base.Theme.AppCompat.Light" parent="Base.V21.Theme.AppCompat.Light"/>
<style name="Base.V21.Theme.AppCompat.Light" parent="Base.V7.Theme.AppCompat.Light">
<style name="Base.V7.Theme.AppCompat.Light" parent="Platform.AppCompat.Light">
<style name="Platform.AppCompat.Light" parent="Platform.V21.AppCompat.Light"/>
<style name="Platform.V21.AppCompat.Light" parent="android:Theme.Material.Light.NoActionBar">
android:theme="@style/Theme.MaterialComponents.DayNight.DarkActionBar"