How to get the default text color for android TextView?

25,748

Solution 1

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

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

or

#808080

It worked great for me!

Solution 2

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

Solution 3

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

Share:
25,748
Burrich
Author by

Burrich

Updated on June 01, 2020

Comments

  • Burrich
    Burrich almost 4 years

    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.