将包括textColor在内的样式应用于text时,文本的颜色不会更改 [英] Color of the text is not changing when style including textColor is applied to textAppearance of textView
问题描述
我想减少我的xml代码重复。因此,我为textView中的文本制作了一些标准样式。我们可以在textView的样式属性和 android:textAppearance属性下应用样式。
I want to reduce my xml code repetition. So I made some standard styles for text in textView. We can apply styles under 'style' attribute as well as 'android:textAppearance' attribute in textView.
以下是我为显示文字而制作的一些样式-
Below are some styles I made for text appearance-
<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的样式属性下工作。
When I apply these styles under 'textAppearance' attribute the color of the text is not changing in none of the above styles. It's working under 'style' attribute of textView.
//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下应用其他样式'属性。根据 Android文档,我们可以在'textAppearance'下应用textColor样式属性。
I want them to work under 'textAppearance' attribute so that I can apply some other style under 'style' attribute. And according to android documentation we can apply textColor styles under 'textAppearance' attribute.
请为此提出一些解决方案。
谢谢
Please suggest some solution to this. Thanks
推荐答案
尝试将小部件中的文本颜色设置为null,例如:
Try setting the text color in your widget as null like this:
<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。导入和链接问题有时可以像这样解决。
Also, I think you should try to Invalidate cache and Restart Android Studio. Import and linking issues can be solved like this sometimes.
这篇关于将包括textColor在内的样式应用于text时,文本的颜色不会更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!