我想减少 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>
当我在“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"/>
我希望它们在“textAppearance”属性下工作,以便我可以在“style”属性下应用一些其他样式。并根据安卓文档 https://developer.android.com/guide/topics/ui/themes.html我们可以在“textAppearance”属性下应用textColor样式。
请提出一些解决方案。
谢谢
尝试将小部件中的文本颜色设置为 null,如下所示:
<TextView
android:id="@+id/profile_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Full Name"
android:textColor="@null" //add this line
android:textAppearance="@style/CodeFont"/>
另外,我认为你应该尝试使缓存无效并重新启动 Android Studio。导入和链接问题有时可以这样解决。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)