What is default color for text in textview?

…衆ロ難τιáo~ 提交于 2019-12-18 10:25:04

问题


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 ?


回答1:


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.




回答2:


Actually the color TextView is:

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

or

#808080



回答3:


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

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



回答4:


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



回答5:


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




回答6:


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

textPrimaryColor = #000000

and

textColorPrimaryDark = #757575



回答7:


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




回答8:


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




回答9:


hey you can try this

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



回答10:


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



来源:https://stackoverflow.com/questions/6468602/what-is-default-color-for-text-in-textview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!