在 Jelly Bean (4.1) 設備上,Spinner 與 NumberPicker 呈現 Gingerbread (2.x) 風格,而非 Holo 主題。即使在 XML 中設定 style="@android:style/Theme.Holo" 也無效。
style 屬性僅套用於單一 View,不會改變整個 Activity/Application 的主題。且 Theme.Holo 是應用/Activity 級主題,不可直接用於 View 的 style。
在 AndroidManifest.xml 設定應用主題:
<application android:theme="@style/MyTheme" ...>
定義版本化主題資源:
<!-- res/values/styles.xml -->
<style name="MyTheme" parent="android:Theme.Light"></style>
<!-- res/values-v11/styles.xml -->
<style name="MyTheme" parent="android:Theme.Holo.Light"></style>
若僅需特定 Spinner 使用 Holo 風格:
<Spinner
android:id="@+id/spinnermap"
style="@style/MySpinner"
... />
<!-- res/values/styles.xml -->
<style name="MySpinner" parent="android:Widget.Spinner"></style>
<!-- res/values-v11/styles.xml -->
<style name="MySpinner" parent="android:Widget.Holo.Spinner"></style>
使用 android:Widget.Holo.NumberPicker 作為 v11 以上的 parent。
透過版本限定資源目錄(values-v11 等)定義不同父主題,系統會自動依 API 等級選擇正確樣式,徹底解決跨版本主題不一致問題。