android 讀取 attr 資源

在layout中:

<TextView

        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:text="A"
        android:textSize="?normal_font_size"

         />

在attrs.xml中

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <attr name="normal_font_size" format="dimension" />
</resources>

 

在themes.xml中

  <style name="MainTheme" parent="@android :style/Theme.Black.NoTitleBar">
        <item name="normal_font_size">15px</item>
    </style> 

問題:在代碼中如何動態讀取我在主題中定義的值?

 

只要用setTheme(R.style.MainTheme)就可以了

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章