在颜色值中使用?android:attr颜色时出现通货膨胀异常
为了使应用程序暗模式兼容,我正在尝试使用中建议的颜色属性。我用Material.DayNight主题作为风格在颜色值中使用?android:attr颜色时出现通货膨胀异常,android,android-xml,inflate-exception,android-dark-theme,Android,Android Xml,Inflate Exception,Android Dark Theme,为了使应用程序暗模式兼容,我正在尝试使用中建议的颜色属性。我用Material.DayNight主题作为风格 <style name="LightCustomFontStyle" parent="Theme.MaterialComponents.DayNight.NoActionBar"> 这是我的colors.xml文件 <color name="content_text_color">?android:
<style name="LightCustomFontStyle" parent="Theme.MaterialComponents.DayNight.NoActionBar">
这是我的colors.xml文件
<color name="content_text_color">?android:attr/textColorPrimary</color>
<color name="label_text_color">?android:attr/textColorSecondary</color>
<color name="colorControlNormal">?android:attr/colorControlNormal</color>
<color name="colorBackground">?android:attr/colorBackground</color>
android:attr/textColorPrimary
?android:attr/textColorSecondary
?android:attr/colorControlNormal
?android:attr/colorBackground
但是当我试图在我的布局中使用这些属性时,它们与android.view.InflateException一起崩溃,我不理解原因。例如,在视图中,当我尝试像这样设置背景色时。当我尝试设置textColor属性时也是一样的
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorBackground">
所以我不明白问题是什么,我想知道是否有可能像这样使用这些属性。谢谢你提前帮忙