Reputation: 155
Good Day, I have this style:
<style name="ViewPagerTitleStrip">
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:textColor">#FFFFFF</item>
<item name="android:textSize">14sp</item>
</style>
I would like to change textColor in this method:
void setFontColor(){
SharedPreferences mPref = this.getSharedPreferences(Constants.USER_SETTINGS_PREF, Context.MODE_PRIVATE);
boolean colorPref = mPref.contains(Constants.USER_FONT_COLOR);
if(colorPref){
int color = mPref.getInt(Constants.USER_FONT_COLOR, -1);
//Somewhere here
}
}
How can I implement that that ?
Upvotes: 1
Views: 374
Reputation: 67189
You cannot change XML resources at runtime.
You can, however, get the color value from your SharedPreferences and apply it directly to the View.
For example, assuming your view has a setTextColor()
method:
if (colorPref) {
int color = mPref.getInt(Constants.USER_FONT_COLOR, -1);
titleStrip.setTextColor(color);
}
Upvotes: 1