7

I cannot get the default gray text color for TextView (and maybe other views) in Android 23.

I tried to get it with this code :

TextView textview= (TextView) mActivity.findViewById(R.id.my_textview);

int colorFirstTry = title.getCurrentTextColor(); // black
int colorSecondTry = title.getTextColors().getDefaultColor(); // black
int colorthirdTry = ContextCompat.getColor(mActivity, android.R.color.primary_text_light); // black

My theme is the default theme used in an blank activity project (AppTheme from Theme.AppCompat.Light.DarkActionBar parent). Colors are blue, darker blue and purple for respectively colorPrimary, colorPrimaryDark and colorAccent.

When i navigate through all Theme.AppCompat.Light.DarkActionBar parents, i find a similar gray value :

<style name="Base.V7.Theme.AppCompat.Light" parent="Platform.AppCompat.Light">   
    ...
    <item name="colorPrimaryDark">@color/primary_dark_material_light</item>

But this value shoud be overrided by my app theme value.

Burrich
  • 1,214
  • 1
  • 16
  • 15

3 Answers3

30

As said by Alex here, you can get it by:

android:textColor="@android:color/tab_indicator_text"

or

#808080

It worked great for me!

Community
  • 1
  • 1
Alysson Myller
  • 1,203
  • 11
  • 13
  • 4
    Worked great! I used it programmatically in this way: `textView.setTextColor(getResources().getColor(android.R.color.tab_indicator_text));` – Hasan Abdullah Jan 07 '19 at 06:31
3

please check this answer:

You can save old color and then use it to restore the original value. Here is an example:

ColorStateList oldColors =    textView.getTextColors(); //save original colors
textView.setTextColor(Color.RED);
....
textView.setTextColor(oldColors);//restore original colors

But in general default TextView text color is determined from current Theme applied to your Activity.

From: What is default color for text in textview?

Hope it help

Community
  • 1
  • 1
piotrek1543
  • 19,130
  • 7
  • 81
  • 94
1

Best way according to google is

title.setTextColor(Color.parseColor("#000000"));
title.setAlpha(0.54f);

when you want set other color reset the alpha to 1.0f

source: Google Material Design

Karan Modi
  • 972
  • 2
  • 13
  • 26
Tiago Oliveira
  • 1,582
  • 1
  • 16
  • 31