我最终为 xml 添加了样式,这样感觉更干净,而且我有更多的控制权。
每个布局 xml(包括 EditText、AutoCompleteTextView)
<TextView
style="?textTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/ref" />
attrs.xml
<attr name="textTitle" format="reference" />
styles.xml(请注意,我也覆盖了微调器样式以保持大小一致
<style name="AppTheme.Small">
<item name="textTitle">@style/small_title_text</item>
<item name="android:spinnerItemStyle">@style/spinner_small</item>
</style>
<style name="AppTheme.Medium">
<item name="textTitle">@style/medium_title_text</item>
<item name="android:spinnerItemStyle">@style/spinner_medium</item>
</style>
<style name="AppTheme.Large">
<item name="textTitle">@style/large_title_text</item>
<item name="android:spinnerItemStyle">@style/spinner_large</item>
</style>
<!-- SMALL FONT SIZE -->
<style name="small_title_text">
<item name="android:textSize">15sp</item>
<item name="android:textStyle">bold</item>
</style>
<!-- MEDIUM FONT SIZE -->
<style name="medium_title_text">
<item name="android:textSize">19sp</item>
<item name="android:textStyle">bold</item>
</style>
<style name="medium_list_text"></style>
<!-- LARGE FONT SIZE -->
<style name="large_title_text">
<item name="android:textSize">23sp</item>
<item name="android:textStyle">bold</item>
</style>
<style name="large_list_text"></style>
<!-- SPINNER STYLES -->
<style name="spinner_small">
<item name="android:textSize">17sp</item>
<item name="android:paddingTop">0dip</item>
</style>
<style name="spinner_medium">
<item name="android:textSize">21sp</item>
<item name="android:paddingTop">0dip</item>
</style>
<style name="spinner_large">
<item name="android:textSize">25sp</item>
<item name="android:paddingTop">0dip</item>
</style>
然后我在创建每个活动之前设置主题。
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
PreferenceHelper mPrefs = PreferenceHelper.getInstance(this);
setTheme(mPrefs.getTheme());
setContentView(R.layout.activity_list);