2015-09-04 19 views
0

我想通過應用程序添加動態字體更改設置。我使用了典型的樣式和attr方法,但是我收到了這個警告。Android Studio - 渲染問題,屬性文本大小無效

渲染問題屬性「textSize」中的「?attr/font_medium」不是有效的格式。 (未示出16個類似的錯誤)

實施例的TextView

<TextView 
        android:id="@+id/labelWeeks" 
        android:layout_width="wrap_content" 
        android:gravity="center" 
        android:layout_height="wrap_content" 
        android:layout_gravity="center" 
        android:paddingLeft="2dp" 
        android:paddingRight="2dp" 
        style="@style/TextViewStyle" 
        android:textColor="@color/app_white"/> 

我style.xml具有此

<style name="TextViewStyle"> 
    <item name="android:layout_width">wrap_content</item> 
    <item name="android:layout_height">wrap_content</item> 
    <item name="android:text">@string/app_name</item> 
    <item name="android:ellipsize">end</item> 
    <item name="android:textSize">?attr/font_small</item> 
</style> 

和attr.xml具有此

<declare-styleable name="FontStyle"> 
    <attr name="font_small" format="dimension" /> 
    <attr name="font_medium" format="dimension" /> 
    <attr name="font_large" format="dimension" /> 
</declare-styleable> 

所以,這是什麼警告是關於和如何reslove它

回答

0

你attr.xml文件無關使用attr/some_attribute引用? <declare-styleable>標籤是用於定義自定義視圖屬性,如查看有「layout_width」和「layout_height」等(learn more about declare-styleable

定義自定義尺寸使用RES /價值/ dimens.xml文件,並定義你的價值觀這樣:

<resources> 
    <dimen name="font_small">12sp</dimen> 
    <dimen name="font_medium">14sp</dimen> 
    <dimen name="font_large">16sp</dimen> 
</resources> 

然後引用它們:

<style name="TextViewStyle"> 
    <item name="android:layout_width">wrap_content</item> 
    <item name="android:layout_height">wrap_content</item> 
    <item name="android:text">@string/app_name</item> 
    <item name="android:ellipsize">end</item> 
    <item name="android:textSize">@dimen/font_small</item> 
</style>