If I set color easy way, like this android:textColor=?myThemeVariable, then I getting iflating error.
How to resolve that trouble?
CodePudding user response:
If I understood correctly what you are looking for is that your TextView or whatever view to be aligned with your configuration of dark-mode and light-mode, right?
So you'd need to have two style.xml files.
- res/drawable/values/themes.xml
- res/drawable/values/themes.xml(night)
Inside of each one you need to assign the color as follows :
<item name="android:textColorPrimary">@color/white</item> (night)
<item name="android:textColorPrimary">@color/black</item> (light)
So whenever you want to follow that rule in your TextView you can use ?android:textColorPrimary as follows :
android:textColor = "?android:textColorPrimary"
Another option is instead of using themes you can create two colors.xml
- values/colors.xml
- values-night/colors.xml
Then there you have the color with the same name but changing the hex, so instead of having what you have
<color name="md_theme_light_text_color">#000000</color>
<color name="md_theme_dark_text_color">#ffffff</color>
On each colors.xml use :
<color name="textColor">#000000</color> //values/colors.xml
<color name="textColor">#ffffff</color> //values-nigh/colors.xml
So in your xml you can use textColor as follows :
android:textColor = "@color/textColor"
