在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)就可以了