我想这样做:
textView.setTextColor(R.attr.myColor)
这是因为我为夜间模式和光照模式都创建了一个自定义颜色
attr.xml
<resources>
<attr name="myColor" format="reference|color" />
themes.xml
<item name="textMessageColor">@color/black</item>
themes-night.xml
<item name="textMessageColor">@color/white</item>
但是每当我使用它时,它就不起作用。
在xml中试试<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="?myColor"/>