微调框背景在Android 6.0+上不正确

时间:2018-09-05 08:55:43

标签: android android-spinner

我在Eclipse上使用Android项目(旧项目)。

我从这里安装ADT:

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

在我的manifest.xml中

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

xml布局的片段:

  <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" />

在这里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>

可绘制 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>

此处res\drawable-mdpi\spinner_pressed_custom.9.png

enter image description here

这是Android 4.3上的结果 enter image description here

,这是Android 6.0+上的结果 enter image description here

在此处单击微调器: enter image description here

如您所见,微调框的背景与Android 4.0不同。在android 4.0上。是正确的微调器背景。但是在android 6.0+中是不正确的。

结果9路径发生器 enter image description here

为什么?

2 个答案:

答案 0 :(得分:0)

enter image description here 我认为这是dpi的问题,所以我建议您根据dpi制作9个补丁图像

转到下方链接

Click Here

并将您当前的9个补丁图像拖到此处,它将根据dpi生成图像。

答案 1 :(得分:0)

由于您不是通过编程方式设置渐变背景,所以问题就出在已弃用主题中使用的样式:Widget.Holo.Light.Spinner

只需将其替换为最新主题,例如Widget.AppCompat.Light.Spinner

如果您可以选择的话,也可以尝试更新targetSdkVersion并使用更新的SDK版本。

一些澄清: 在新的Android版本上渐变被破坏的真正原因是在dp中指定值的新要求,请参见Android Gradient on Lollipop not working. - API 21