What is default color for text in textview?

Viewed 120700

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

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

textPrimaryColor = #000000

and

textColorPrimaryDark = #757575

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

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

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

hey you can try this

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

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

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

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