textview中文本的默认颜色是什么?

Luk*_*kap 70 android default colors textview android-gui

我将颜色设置为红色,然后我想再次将颜色设置回默认值,但我不知道什么是默认颜色,有谁知道?

Ale*_*aos 82

实际上TextView的颜色是:

android:textColor="@android:color/tab_indicator_text"
Run Code Online (Sandbox Code Playgroud)

要么

#808080
Run Code Online (Sandbox Code Playgroud)

  • 非常接近,但这种颜色不一样. (4认同)
  • 这是默认的标签指示器文本颜色.在许多情况下,它可能与默认文本颜色相同,但我不会依赖它. (3认同)
  • @LukTar 是对的,我使用了 photoshop 并检查了颜色...#737373 是在 android studio 中放大到 1000% 的视图上的点像素样本(一个像素的样本区域大小)的 textview 文本颜色...我想您需要查看应用程序的默认样式以获取任何特定应用程序的实际值... (2认同)

ina*_*ruk 77

您可以保存旧颜色,然后使用它来恢复原始值.这是一个例子:

ColorStateList oldColors =  textView.getTextColors(); //save original colors
textView.setTextColor(Color.RED);
....
textView.setTextColor(oldColors);//restore original colors
Run Code Online (Sandbox Code Playgroud)

但一般来说,默认TextView文本颜色是根据应用于您的当前主题确定的Activity.

  • @shiouming 取决于所使用的上下文。每个构造函数都使用一个上下文,并且在该上下文中设置了一个主题(通常是默认值)。如果需要,请使用 [TextView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes)](https://developer.android.com/reference/android/widget/TextView.html#TextView(android.content.Context, %20android.util.AttributeSet,%20int,%20int)) (2认同)

dav*_*pcj 36

有一些默认颜色定义 android.R.color

int c = getResources().getColor(android.R.color.primary_text_dark);
Run Code Online (Sandbox Code Playgroud)

  • 从API level23开始,`getResources().getColor(int id)`现已弃用(参见[link](https://developer.android.com/reference/android/content/res/Resources.html#getColor%28int) %29)).你可以使用`getResources().getColor(int id,Resources.Theme theme)`或`ContextCompat.getColor(contex,android.R.color.primary_text_dark)` (5认同)
  • 它应该是`int c = ...`而不是`Color c = ...` (4认同)

Bon*_*dax 13

从属性中获取这些值:

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();
Run Code Online (Sandbox Code Playgroud)


Ahm*_*aee 8

我知道它很旧,但根据我自己的主题编辑器,默认的浅色主题,默认

textPrimaryColor = #000000

textColorPrimaryDark = #757575
Run Code Online (Sandbox Code Playgroud)


pat*_*ckf 6

如果您没有指定文本颜色,Android会使用主题中的默认值.在各种Android UI中可能会有不同的颜色(例如HTC Sense,Samsung TouchWiz等).Android有一个_dark_light主题,所以这些默认值是不同的(但在vanilla android中它们几乎都是黑色).但是,最好自己定义主要文本颜色,以便在整个设备中提供一致的样式.

在代码中:

getResources().getColor(android.R.color.primary_text_dark);
getResources().getColor(android.R.color.primary_text_light);
Run Code Online (Sandbox Code Playgroud)

在xml中:

android:color="@android:color/primary_text_dark"
android:color="@android:color/primary_text_light"
Run Code Online (Sandbox Code Playgroud)

作为vanilla Android中的参考,黑暗主题文本颜色是自API API以来#060001的光主题#060003.在这里查看android样式类


Chu*_*uck 5

这可能并非在所有情况下都是可行的,但为什么不简单地使用同一 Activity 中存在的不同随机 TextView 的值,并且该 TextView 带有您正在寻找的颜色呢?

txtOk.setTextColor(txtSomeOtherText.getCurrentTextColor());
Run Code Online (Sandbox Code Playgroud)