Getting the default TextView textColor in Android for the current theme

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.textColor
  • android.R.attr.textColorPrimary
  • android.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?

+5
source share
1 answer

Based on the TextView code in here should be android.R.styleable.TextAppearance_textColor

0
source

All Articles