What is default color for text in textview?

AndroidColorsTextviewDefaultAndroid Gui

Android Problem Overview


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 ?

Android Solutions


Solution 1 - Android

Actually the color TextView is:

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

or

#808080

Solution 2 - Android

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.

Solution 3 - Android

There are some default colors defined in android.R.color

int c = getResources().getColor(android.R.color.primary_text_dark);

Solution 4 - Android

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();

Solution 5 - Android

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

Solution 6 - Android

I know it is old but according to my own theme editor with default light theme, default

textPrimaryColor = #000000

and

textColorPrimaryDark = #757575

Solution 7 - Android

I used a color picker on the textview and got this #757575

Solution 8 - Android

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());

Solution 9 - Android

There is no default color. It means that every device can have own.

Solution 10 - Android

I believe the default color integer value is 16711935 (0x00FF00FF).

Solution 11 - Android

> hey you can try this

ColorStateList colorStateList = textView.getTextColors();
String hexColor = String.format("#%06X", (0xFFFFFF & colorStateList.getDefaultColor()));

Solution 12 - Android

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

Solution 13 - Android

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)
}

Solution 14 - Android

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();
    }

Solution 15 - Android

The color of text inside a TextView is totally dependent on your theme. The easiest way to know it:

  1. Add a TextView to any xml file
  2. Select the TextView
  3. Click on Split view
  4. Open the Attributes tab and scroll to the color section.

enter image description here

As you can see, according to my theme it is: @android:color/secondary_text_material_light

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionLukapView Question on Stackoverflow
Solution 1 - AndroidAlex ZaraosView Answer on Stackoverflow
Solution 2 - AndroidinazarukView Answer on Stackoverflow
Solution 3 - AndroiddavenpcjView Answer on Stackoverflow
Solution 4 - AndroidBondaxView Answer on Stackoverflow
Solution 5 - AndroidPatrick FavreView Answer on Stackoverflow
Solution 6 - AndroidAhmad Reza EnshaeeView Answer on Stackoverflow
Solution 7 - Androiddave o gradyView Answer on Stackoverflow
Solution 8 - AndroidChuckView Answer on Stackoverflow
Solution 9 - AndroidpiotrpoView Answer on Stackoverflow
Solution 10 - AndroidC NickView Answer on Stackoverflow
Solution 11 - AndroidVivek Pratap SinghView Answer on Stackoverflow
Solution 12 - AndroidquealegriamasalegreView Answer on Stackoverflow
Solution 13 - AndroidArstView Answer on Stackoverflow
Solution 14 - AndroidVitalyView Answer on Stackoverflow
Solution 15 - AndroidSalam El-BannaView Answer on Stackoverflow