[android] What is default color for text in textview?

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 ?

This question is related to android colors textview default android-gui

The answer is


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


hey you can try this

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

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


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

textPrimaryColor = #000000

and

textColorPrimaryDark = #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());

Actually the color TextView is:

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

or

#808080

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


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


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

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

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

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


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

Examples related to android

Under what circumstances can I call findViewById with an Options Menu / Action Bar item? How to implement a simple scenario the OO way My eclipse won't open, i download the bundle pack it keeps saying error log getting " (1) no such column: _id10 " error java doesn't run if structure inside of onclick listener Cannot retrieve string(s) from preferences (settings) strange error in my Animation Drawable how to put image in a bundle and pass it to another activity FragmentActivity to Fragment A failure occurred while executing com.android.build.gradle.internal.tasks

Examples related to colors

is it possible to add colors to python output? How do I use hexadecimal color strings in Flutter? How do I change the font color in an html table? How do I print colored output with Python 3? Change bar plot colour in geom_bar with ggplot2 in r How can I color a UIImage in Swift? How to change text color and console color in code::blocks? Android lollipop change navigation bar color How to change status bar color to match app in Lollipop? [Android] How to change color of the back arrow in the new material theme?

Examples related to textview

Kotlin: How to get and set a text to TextView in Android using Kotlin? How to set a ripple effect on textview or imageview on Android? The specified child already has a parent. You must call removeView() on the child's parent first (Android) Android: Creating a Circular TextView? android on Text Change Listener Android - Set text to TextView Placing a textview on top of imageview in android Rounded corner for textview in android Different font size of strings in the same TextView Auto-fit TextView for Android

Examples related to default

Why Is `Export Default Const` invalid? Default Values to Stored Procedure in Oracle How do I change the default index page in Apache? Angularjs Template Default Value if Binding Null / Undefined (With Filter) Google Chrome default opening position and size new DateTime() vs default(DateTime) Using an attribute of the current class instance as a default value for method's parameter How do I set the default schema for a user in MySQL In NetBeans how do I change the Default JDK? PHP sessions default timeout

Examples related to android-gui

What is default color for text in textview?