old theme in 4.0+ app

2019-09-02 19:38发布

问题:

I've created a spinner in my activity and when i run my app on my Jelly Bean device the theme of the spinner is like 2.x, how can i get the ICS one?

Here's my spinner code :

    <Spinner
      android:id="@+id/spinnermap"
      style="@android:style/Theme.Holo"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_alignParentLeft="true"
      android:layout_centerVertical="true" />

As you can see I tried to set the global style "Holo" but no results..

I had the same problem with a NumberPicker but can't remember how I fixed it.

回答1:

  style="@android:style/Theme.Holo"

This is not the solution. You won't have a fallback on pre HC devices. You need to declare a Theme for your whole application if you want to use the holo theme in your whole app for HC+(I assume this is what you want to have).

In your Manifest:

android:theme="@style/MyTheme"

values/styles.xml:

<style name="MyTheme" parent="android:Theme.Light">
</style>

values-v11/styles.xml:

<style name="MyTheme" parent="android:Theme.Holo.Light">
</style>

Now you'll have a dropdown spinner on HC+(and also other holo widgets of course)


However if you just want to have the spinner to be "holofied" you can do this:

<Spinner
      android:id="@+id/spinnermap"
      style="@style/MySpinner"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_alignParentLeft="true"
      android:layout_centerVertical="true" />

values/styles.xml:

<style name="MySpinner" parent="android:Widget.Spinner">
</style>

values-v11/styles.xml:

<style name="MySpinner" parent="android:Widget.Holo.Spinner">
</style>