レイアウトでダークモードを使用したい。私はこれを試しました:
attr.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<attr name="myColor" format="reference|color" />
</resources>
themes.xml:
<resources xmlns:tools="http://schemas.android.com/tools">
...
<!-- Light -->
<item name="myColor">#4A4A4A</item>
...
<!-- Dark-->
<item name="myColor">#FFFFFF</item>
</resources>
レイアウト.xml:
<androidx.cardview.widget.CardView
style="@style/HBCardContent"
android:textDirection="locale">
<TextView
android:id="@+id/my_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World"
android:textColor="?attr/myColor"/>
</androidx.cardview.widget.CardView>
しかし、私はこのエラーが発生しました:
Unable to start activity ... Binary XML file line #53 in com.example.xxx:layout/layout: Error inflating class <unknown>
これを行う別の方法はありますか?