values 包下
attrs.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
+ <attr name="cancle_search" format="color" />
</resources>
themes.xml
<style name="Theme.Testdelete" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
...
<!-- Customize your theme here. -->
+ <item name="cancle_search">@color/text_search_color</item>
</style>
colos.xml
<color name="text_search_color">#FF000000</color>
values-night 包下
themes.xml
<!-- Base application theme. -->
<style name="Theme.Testdelete" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
...
<!-- Customize your theme here. -->
+ <item name="cancle_search">@color/text_search_color</item>
</style>
colors.xml
<color name="text_search_color">#ffffff</color>
使用
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
+ android:textColor="?attr/cancle_search" />
</LinearLayout>