0

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?

Sagar D
  • 2,588
  • 1
  • 18
  • 31

1 Answers1

1

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);
Sagar D
  • 2,588
  • 1
  • 18
  • 31
  • give a error : "Cannot make a static reference to the non-static method setTheme(int) from the type ContextThemeWrapper" – Er Swati Mittal Sep 01 '14 at 10:37
  • check my edit, I'm assuming that you are calling `setTheme()` from your activity – Sagar D Sep 01 '14 at 10:43
  • It is not working.and by this code can i change the textcolor of all textview which is using in my application – Er Swati Mittal Sep 01 '14 at 10:48
  • can i set the color using color picker have you any code for this – Er Swati Mittal Sep 01 '14 at 10:48
  • post your full code where you are trying to change the theme – Sagar D Sep 01 '14 at 10:51
  • this.setTheme(R.style.yourcorrespondingtheme); by using this code it can change the color only spinner list item,but i want to change the color of all textview which is using in app – Er Swati Mittal Sep 01 '14 at 11:09
  • case R.id.spinback: ((TextView) spinbset.getSelectedView()).setTextColor(getResources().getColor(R.color.White)); String getcol = spinbset.getSelectedItem().toString(); if(getcol.equals("Red")){ this.setTheme(R.style.styleRED); } if(getcol.equals("Green")){ this.setTheme(R.style.styleGreen); } break; }} – Er Swati Mittal Sep 16 '14 at 06:46
  • this is my code ,by this code i can change the color of only spinner item of id spinback but i want to change the color of all textview which is use in my whole project by select the color from spinner.. – Er Swati Mittal Sep 16 '14 at 06:48