I set the color to red , and after that I want to set the color again back to default, but I do not know what is default color, does anyone knows ?
15 Answers
Actually the color TextView is:
android:textColor="@android:color/tab_indicator_text"
or
#808080

- 6,443
- 2
- 26
- 21
-
5That is the default tab indicator text color. In many cases it may be the same as the default text color, but I wouldn't rely on it. – k2col Oct 20 '15 at 19:24
-
8Very close, but this colour is not the same. – LukaszTaraszka Apr 16 '17 at 12:47
-
2@LukTar is right, I used photoshop and checked the color... #737373 is the textview text color from a point pixel sample (sample area size of one pixel) on a view zoomed to 1000% in android studio... i think you need to look at the app's default style to get the actual value for any particualr app though... – me_ Sep 11 '18 at 07:04
-
Also, it does not exists in `marshmallow` – Jagar Jun 14 '22 at 07:13
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
.

- 74,247
- 24
- 188
- 156
-
-
From my observation, text color defined by theme is not inherited by TextView added dynamically from code. It always appears in white regardless of dark/light theme. – shiouming Dec 20 '17 at 23:54
-
2@shiouming Depends of the Context used. Every Constructor uses a Context, and in that Context, a Theme is set (usually default). If needed, use the [TextView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes)](https://developer.android.com/reference/android/widget/TextView.html#TextView(android.content.Context,%20android.util.AttributeSet,%20int,%20int)) – Bonatti Sep 26 '18 at 13:50
-
But! After for example theme changing oldColors was color for old theme - so it's not completely working solution. As alternative: You can add to the layout invisible TextView - and get default text color from it. – Vitaly Aug 12 '21 at 06:19
There are some default colors defined in android.R.color
int c = getResources().getColor(android.R.color.primary_text_dark);

- 3,804
- 7
- 33
- 60

- 12,508
- 5
- 40
- 37
-
4
-
7As of API level23, `getResources().getColor(int id)` is now deprecated (see [link](https://developer.android.com/reference/android/content/res/Resources.html#getColor%28int%29)). You can either use `getResources().getColor (int id, Resources.Theme theme)` or `ContextCompat.getColor(contex, android.R.color.primary_text_dark)` – InfectedPacket Dec 30 '15 at 18:56
-
1
Get these values from attributes:
int[] attrs = new int[] { android.R.attr.textColorSecondary };
TypedArray a = getTheme().obtainStyledAttributes(R.style.AppTheme, attrs);
DEFAULT_TEXT_COLOR = a.getColor(0, Color.RED);
a.recycle();

- 3,143
- 28
- 35
-
This looks like it will properly select the colour based on theme, and will update for instance, if the app is in night mode. – Brill Pappin Aug 26 '15 at 15:47
-
To get the TypedArray for the current Theme call it without the Theme arg: TypedArray a = getTheme().obtainStyledAttributes(attrs); – petrsyn Mar 09 '16 at 08:59
-
1This will only get an appropriate color if the theme is actually using textColorSecondary. Since it is possible to override this in a theme or style, this is not a very accurate way of determining what the default text color for a particular view will actually be. Note also that individual views can now be themed, so the theme associated with the view's context should be used instead of assuming the activity's theme is in effect for all of its views. – Lorne Laliberte Oct 03 '16 at 22:58
There are defaults in the theme that Android uses if you don't specifiy a text color. It may be different colors in various Android UIs (e.g. HTC Sense, Samsung TouchWiz, etc). Android has a _dark
and _light
theme, so the defaults are different for these (but nearly black in both of them in vanilla android). It is however good practice to define your primary text color yourself for to provide a consistent style throughout the devices.
In code:
getResources().getColor(android.R.color.primary_text_dark);
getResources().getColor(android.R.color.primary_text_light);
In xml:
android:color="@android:color/primary_text_dark"
android:color="@android:color/primary_text_light"
As reference in vanilla Android the dark theme text color is #060001
and the in the light theme it's #060003
since API v1. See the android style class here

- 33,984
- 10
- 106
- 126
-
The colors referenced in your last link are actually not colors at all, they are just android.R values that are used to look up the color. You can look up the default colors by finding the color in [this directory](https://android.googlesource.com/platform/frameworks/base/+/master/core/res/res/color/) and looking up the base color reference in [this .xml file](https://android.googlesource.com/platform/frameworks/base/+/master/core/res/res/values/colors.xml). – Alex Gittemeier May 07 '19 at 03:34
I know it is old but according to my own theme editor with default light theme, default
textPrimaryColor = #000000
and
textColorPrimaryDark = #757575

- 336
- 6
- 13
It may not be possible in all situations, but why not simply use the value of a different random TextView that exists in the same Activity and that carries the colour you are looking for?
txtOk.setTextColor(txtSomeOtherText.getCurrentTextColor());

- 1,110
- 3
- 15
- 22
The color of text inside a TextView
is totally dependent on your theme.
The easiest way to know it:
- Add a
TextView
to any xml file - Select the
TextView
- Click on
Split
view - Open the
Attributes
tab and scroll to the color section.
As you can see, according to my theme it is: @android:color/secondary_text_material_light

- 3,784
- 1
- 22
- 34
hey you can try this
ColorStateList colorStateList = textView.getTextColors();
String hexColor = String.format("#%06X", (0xFFFFFF & colorStateList.getDefaultColor()));

- 1,564
- 16
- 26
I found that android:textColor="@android:color/secondary_text_dark"
provides a closer result to the default TextView color than android:textColor="@android:color/tab_indicator_text"
.
I suppose you have to switch between secondary_text_dark/light depending on the Theme you are using

- 2,887
- 1
- 13
- 35
You could use TextView.setTag/getTag to store original color before making changes. I would suggest to create an unique id resource in ids.xml to differentiate other tags if you have.
before setting to other colors:
if (textView.getTag(R.id.txt_default_color) == null) {
textView.setTag(R.id.txt_default_color, textView.currentTextColor)
}
Changing back:
textView.getTag(R.id.txt_default_color) as? Int then {
textView.setTextColor(this)
}

- 3,098
- 1
- 35
- 42
I believe the default color integer value is 16711935 (0x00FF00FF).

- 2,500
- 2
- 17
- 21
-
12wow hardcoded stuff, you know. Was this the value for all Android versions on all devices and with all selectable themes?! Joking, You know... :) – Bondax Nov 20 '12 at 14:51
-
1So the default text color in android is pink? I think it is more inline with #060001 http://developer.android.com/reference/android/R.color.html#primary_text_dark – Patrick Feb 13 '15 at 17:10
-
There are some default colours which get defined in the Themes of app. Below is the code snippet which you can use to get the current default color programmatically.
protected int getDefaultTextColor(){
TextView textView = new TextView(getContext());
return textView.getCurrentTextColor();
}

- 2,076
- 4
- 34
- 65

- 334
- 4
- 14
There is no default color. It means that every device can have own.

- 12,398
- 7
- 42
- 58
-
9No there are default colors, just that every android distribution can overwrite them – Patrick Feb 13 '15 at 17:26
-