我想减少我的 xml 代码重复。所以我为 textView 中的文本做了一些标准样式。我们可以在 textView 中的 'style' 属性以及 'android:textAppearance' 属性下应用样式。
以下是我为文本外观制作的一些样式-
<style name="Grey">
<item name="android:textColor"> #333333 </item>
</style>
<style name="CodeFont" parent="@android:style/TextAppearance.Medium">
<item name="android:textColor"> #00FF00 </item>
<item name="android:typeface">monospace</item>
<item name="android:textSize">20sp</item>
</style>
Run Code Online (Sandbox Code Playgroud)
当我在 'textAppearance' 属性下应用这些样式时,文本颜色在上述任何样式中都没有改变。它在 textView 的“style”属性下工作。
//textColor not working
<TextView
android:id="@+id/profile_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Full Name"
android:textAppearance="@style/CodeFont"/>
//textColor working
<TextView
android:id="@+id/profile_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Full Name"
style="@style/CodeFont"/>
Run Code Online (Sandbox Code Playgroud)
我希望它们在“textAppearance”属性下工作,以便我可以在“style”属性下应用一些其他样式。根据android 文档,我们可以在 'textAppearance' 属性下应用 textColor 样式。
请对此提出一些解决方案。谢谢