2017-07-10 7 views
0

xmlコードの繰り返しを減らしたい。だから、私はtextViewでテキストのいくつかの標準スタイルを作った。 textViewでは 'style'属性と 'android:textAppearance'属性の両方でスタイルを適用できます。以下はtextColorを含むスタイルがtextViewのtextAppearanceに適用されるときに、テキストの色が変化しない

私は「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> 

をappearance-ています。 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」属性の下で仕事をしたいです。 android documentationによると、 'textAppearance'属性の下にtextColorスタイルを適用することができます。

解決策を提案してください。 おかげ

答えて

0

は、このようなヌルとしてウィジェット内のテキストの色を設定してみてください:

<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メーカーを無効にしようとすべきだと思います。インポートとリンクの問題は、このように時々解決できます。

1

このスニペットは、私

<style name="fonts" parent="TextAppearance.AppCompat"> 
    <item name="android:textColor">#245546</item> 
    <item name="android:textSize">30dp</item> 
</style> 

とのTextView

<TextView 
    android:id="@+id/sample" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:text="Welcome to stackoverflow" 
    android:textAppearance="@style/fonts"/> 
であるために働きます
関連する問題