2

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?

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

3 Comments

I want to define the colors on styles.xml and programatically switch them to set the widget colors. Forget about the themes; Now I mean only to colors and switching them. How is the best way to do that.
I think the best way is to declare multiple widget.xml files (for example widget_black.xml or widget_white.xml) with different TextViews ids (for example android:id="@+id/widgetAMPMColorBlack" and set different styles in styles.xml.
Kurtis, check the result here: mogoolab.com/portfolio/android-flowers-clock-widget Thanks again.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.