Reputation: 2672
I want to change the text color of 10-15 TextView
's in my app, when a button is clicked. These text views are not on a single activity. Is there a way to implement this other than using the theme concept.
Upvotes: 1
Views: 1055
Reputation: 3809
You could make an ArrayList
of TextView
and each time you create a TextView (when you first start your app) that you want to change the text color you add it to this ArrayList.
Later on when the user click on your button you call a method which implement a loop on this ArrayList and you set your text color.
A static ArrayList may be needed to achieve this.
ArrayList<TextView> myAlTv = new ArrayList<TextView>();
myAlTv.add(firstTv);
myAlTv.add(secondTv);
myAlTv.add(thirdTv);
//...
public void changeColor()
{
for (int i = 0; i < myAlTv.size(); i++)
{
myAlTv.get(i).setTextColor(0xFFFF0000);
}
}
Upvotes: 3
Reputation: 5157
You can use sharedPreferences to do that . When you click the button you can save the color that the textviews should have into a sharedPreferences object. And then in your other activities you can retrieve those color values via getting the sharedPreference you set before and you can assign those color values to the textviews in the other activities easily.
Upvotes: 2