简体   繁体   中英

Android widget with multiple color themes

What is the best method to set a widget colors theme saved on SharedPreferences. Users choose their preferred colors theme and programatically I set the theme.

For example I have two styles for a TextView with id "widgetThemeDate":

<style name="widgetThemeDate" parent="@style/widgetThemeLight">
        <item name="android:textColor">@color/colorWhite</item>     
</style>

<style name="widgetThemeDate" parent="@style/widgetThemeDark">
        <item name="android:textColor">@color/colorBlack</item>     
</style>

In this case I receive the following error: " error: Resource entry widgetThemeDate already has bag item android:textColor. "

How can I set "widgetThemeDate" color depending user's choice?

You can't set whole themes on a view programatically (see this discussion ), but you can change certain aspects progamatically. For instance. you case you could use the setTextColor() method to change the color of text programatically on ay TextView.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM