Spinner background is not correct on Android 6.0+

Viewed 277

I use Android project(old project) on Eclipse.

I install ADT from here:

https://dl-ssl.google.com/android/eclipse/

In my manifest.xml

<uses-sdk
    android:minSdkVersion="15"
    android:targetSdkVersion="15" />

snippet of xml layout:

  <Spinner
        android:id="@+id/currencySpinner"
        style="@style/racommon_spinner_custom_style"
        android:layout_width="0dip"
        android:layout_height="40dip"
        android:layout_weight="0.3"
        android:prompt="@string/currency" />

here styles.xml

  <style name="racommon_spinner_custom_style" parent="@android:style/Widget.Holo.Light.Spinner">
    <item name="android:background">@drawable/racommon_spinner_custom_bg</item>
    <item name="android:clickable">true</item>
</style>

Here drawable racommon_spinner_custom_bg:

<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:state_focused="true" android:state_pressed="false" android:drawable="@drawable/spinner_selected_custom_border"/>

    <item android:state_focused="true" android:state_pressed="true" android:drawable="@drawable/spinner_pressed_custom"/>

    <item android:drawable="@drawable/spinner_default_custom" />
</selector>

here res\drawable-mdpi\spinner_pressed_custom.9.png

enter image description here

Here result on Android 4.3 enter image description here

and here result on Android 6.0+ enter image description here

Here when click on spinner: enter image description here

As you can see the background of spinner is different than on Android 4.0. On android 4.0. is correct spinner's background. But in android 6.0+ not correct.

Here result nine-pathch generator enter image description here

Why?

2 Answers

enter image description hereI think its a problem of dpi, so i would suggest you make 9 patch image according to dpi

go to Below Link

Click Here

and Drag your current 9 patch image here, it will generate the images according to dpi.

Since you aren't setting gradient background programmatically, the problem is just with the style used from deprecated theme: Widget.Holo.Light.Spinner.

Just replace it with up to date theme like Widget.AppCompat.Light.Spinner.

Also you can try just to update targetSdkVersion and use more recent SDK version if that's an option for you.

Some clarification: the actual cause of the gradients to be broken on newer Android versions is the new requirement to specify values in dp, see Android Gradient on Lollipop not working. - API 21

Related