What is default color for text in textview?

2019-01-31 16:03发布

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 ?

8条回答
霸刀☆藐视天下
2楼-- · 2019-01-31 16:46

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

int c = getResources().getColor(android.R.color.primary_text_dark);
查看更多
欢心
3楼-- · 2019-01-31 16:48

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

查看更多
登录 后发表回答