我想減少我的xml代碼重複。所以我在textView中爲文本製作了一些標準樣式。我們可以在'style'屬性下應用樣式,並在textView中應用'android:textAppearance'屬性。當包含textColor的樣式應用於文本時,文本的顏色不會改變textView的外觀
下面是一些款式我的文字做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的'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'屬性下應用其他一些樣式。根據android documentation,我們可以在'textAppearance'屬性下應用textColor樣式。
請提出一些解決方案。 感謝