Er Swati Mittal
Er Swati Mittal

Reputation: 1

Change text color in style theme by code

How can i change the textcolor of all TextView by changing the textcolor of theme (which is mentioned in style) programmatically??

Example Suppose I want to change the setting in my android application

I have a spinner , and I fill it with different color name. Then how can i change the textcolor of ALL textviews by selected item of spinner.

my default theme is:

<style name="styleN" parent="android:Widget.Holo.Light.TextView">
     <item name="android:textColor">#3DAAB9</item>
    <item name="android:textSize">20dp</item>
    <item name="android:textStyle">bold</item>
</style>

Can someone help me with this?

Upvotes: 0

Views: 483

Answers (1)

Sagar D
Sagar D

Reputation: 2618

Steps do achieve what you are aiming :

1) Create different themes corresponding to each item in the spinner in styles.xml. Let these themes define the different textcolors you want to set.

2) Then, when an item is selected from the spinner, use the following line of code to change the theme of your activity :

 this.setTheme(R.style.yourcorrespondingtheme);

Upvotes: 1

Related Questions