I am trying to reset TextColor TextView at runtime. I would like to get the default color for the TextView as @ColorInt . I believe the current topic knows this.
Here is what I tried:
public @ColorInt int getDefaultThemeColor(int attribute) { TypedArray themeArray = mContext.getTheme().obtainStyledAttributes(new int[] {attribute}); try { int index = 0; int defaultColourValue = 0; return themeArray.getColor(index, defaultColourValue); } finally { themeArray.recycle(); } }
where attribute:
android.R.attr.textColorandroid.R.attr.textColorPrimaryandroid.R.attr.textColorSecondary
None of them worked to get the right color. I also tried replacing the first line of the method:
TypedArray themeArray = mContext.getTheme().obtainStyledAttributes(R.style.AppTheme, new int[] {attribute});
I don't need a dirty solution:
- Retrieving and saving textColor TextView
- color change to
- Reset back to previously saved value
Any clues?
source share