可以使用系统的属性值在布局文件中引用。比如:
这里的?android:textColorPrimary
就是系统定义的属性值,会根据当前的主题(亮/暗模式)自动选择对应的颜色。除了textColorPrimary
,系统还提供了其他属性值,如colorAccent
、colorControlNormal
等。
另外,也可以在代码中使用ContextCompat
类中的getColor
方法获取系统定义的颜色值。比如:
int color = ContextCompat.getColor(context, android.R.color.textColorPrimary);
下一篇:安卓中有任何的调度技术吗?