我将颜色设置为红色,之后我想再次将颜色设置为默认颜色,但我不知道默认颜色是什么,有人知道吗?什么是textview文本的默认颜色?
回答
您可以保存旧颜色,然后使用它恢复原始值。这里有一个例子:
ColorStateList oldColors = textView.getTextColors(); //save original colors
textView.setTextColor(Color.RED);
....
textView.setTextColor(oldColors);//restore original colors
但一般默认TextView
文本颜色从应用到您的Activity
当前的主题。
有在android.R.color
int c = getResources().getColor(android.R.color.primary_text_dark);
它应该是'int c = ...'而不是'Color c = .. ' –
从API级别23起,getResources()。getColor(int id)'现已被弃用(请参阅[link](https://developer.android.com/reference/android/content/res/Resources.html#)的getColor%28int%29))。你可以使用'getResources()。getColor(int id,Resources。主题主题)'或'ContextCompat.getColor(contex,android.R.color.primary_text_dark)' – InfectedPacket
定义了一些默认的颜色属性获取这些值:
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();
这看起来像它会正确选择基于主题的颜色,并将更新,例如,如果应用程序处于夜间模式。 –
若要获取当前主题的TypedArray,则不需要主题参数:TypedArray a = getTheme()。obtainStyledAttributes(attrs); – petrsyn
如果主题实际上使用了textColorSecondary,则只会获得适当的颜色。由于可以在主题或样式中覆盖此值,因此这不是确定特定视图的默认文本颜色实际上的准确方式。 另请注意,个别视图现在可以为主题,所以应该使用与视图的上下文相关联的主题,而不是假设活动的主题对所有视图都有效。 –
有在Android使用,如果你不specifiy文本颜色主题默认值。在各种Android用户界面中可能会有不同的颜色(例如HTC Sense,Samsung TouchWiz等)。 Android有一个_dark
和_light
主题,所以这些默认设置是不同的(但在两个香草android中几乎都是黑色的)。然而,为了在整个设备中提供一致的风格,您自己定义主要文本颜色是一种很好的做法。
在代码:
getResources().getColor(android.R.color.primary_text_dark);
getResources().getColor(android.R.color.primary_text_light);
在XML:
android:color="@android:color/primary_text_dark"
android:color="@android:color/primary_text_light"
如香草的Android参考黑暗题材文本颜色为#060001
和在光的主题是#060003
因为API V1。 See the android style class here
- 1. 什么是TextBlock.Foreground的默认颜色?
- 2. UITableViewCellAccessoryCheckmark的默认颜色是什么?
- 3. 默认UIButton的文本是什么颜色的?
- 4. UITextField中占位符文本的默认颜色是什么?
- 5. theme.appcompat.light的默认文本颜色是什么?
- 6. 什么是jqplot默认系列颜色?
- 7. 什么是默认的TextView Gravity?
- 8. 选择文本时,浏览器默认的背景颜色是什么?
- 9. 更改默认文本颜色网页
- 10. Android。默认文字颜色
- 11. UITabBarController的默认背景颜色是什么?
- 12. 什么是WPF GridViewItem控件的默认Foreground颜色?
- 13. iOS:什么是UITableViewCell的默认背景颜色
- 14. 什么是C#中菜单的默认高亮颜色?
- 15. gnome-terminal的默认背景颜色是什么
- 16. TabItem的默认背景颜色是什么?
- 17. Android 4.0上Holo主题的默认颜色值是什么?
- 18. 什么是WPF对话框的良好默认背景颜色?
- 19. 什么是Android EditText中背景的默认颜色渐变?
- 20. 什么是Holo.Light.DarkActionBar的默认十六进制颜色ActionBar
- 21. 默认的HTML/CSS链接颜色是什么?
- 22. iPhone上的默认TableView节标题背景颜色是什么?
- 23. ListView分隔线的默认颜色是什么?
- 24. 为什么我在TextView中的文本不会改变颜色?
- 25. 什么是Plotly的默认色阶?
- 26. 更改TabView的默认颜色和搜索栏默认颜色
- 27. 为什么引导徽章总是默认颜色?
- 28. Android默认颜色
- 29. ActionBar默认颜色
- 30. 什么是所有Android版本的默认通知背景颜色?
工作非常适合我,谢谢! –
最正确的解决方案。保留文本颜色状态(禁用等) – dasar
从我的观察来看,由主题定义的文本颜色不会由代码中动态添加的TextView继承。它总是以白色显示,无论黑暗/光明的主题。 – shiouming