简体   繁体   English

Android 6.0+上的微调器背景不正确

[英]Spinner background is not correct on Android 6.0+

I use Android project(old project) on Eclipse. 我在Eclipse上使用Android项目(旧项目)。

I install ADT from here: 我从这里安装ADT:

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

In my manifest.xml 在我的manifest.xml中

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

snippet of xml layout: 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" />

here styles.xml 这里是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 : 这里是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 这里res\\drawable-mdpi\\spinner_pressed_custom.9.png

在此输入图像描述

Here result on Android 4.3 这是Android 4.3的结果 在此输入图像描述

and here result on Android 6.0+ 这里的结果是Android 6.0+ 在此输入图像描述

Here when click on spinner: 点击微调器时: 在此输入图像描述

As you can see the background of spinner is different than on Android 4.0. 正如您所看到的,微调器的背景与Android 4.0不同。 On android 4.0. 在Android 4.0上。 is correct spinner's background. 是正确的微调器的背景。 But in android 6.0+ not correct. 但在android 6.0+中不正确。

Here result nine-pathch generator 这里结果九路发电机 在此输入图像描述

Why? 为什么?

在此输入图像描述 I think its a problem of dpi, so i would suggest you make 9 patch image according to dpi 我认为它是dpi的问题,所以我建议你根据dpi制作9个补丁图像

go to Below Link 转到下面的链接

Click Here 点击这里

and Drag your current 9 patch image here, it will generate the images according to dpi. 并在此处拖动当前的9个补丁图像,它将根据dpi生成图像。

Since you aren't setting gradient background programmatically, the problem is just with the style used from deprecated theme: Widget.Holo.Light.Spinner . 由于您没有以编程方式设置渐变背景,因此问题仅在于弃用主题使用的样式: Widget.Holo.Light.Spinner

Just replace it with up to date theme like Widget.AppCompat.Light.Spinner . 只需将其替换为最新的主题,如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. 此外,您可以尝试更新targetSdkVersion并使用更新的SDK版本(如果这是您的选项)。

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. 一些澄清:在较新的Android版本上打破渐变的实际原因是在dp中指定值的新要求,请参阅Lollipop上的Android Gradient无法正常工作。 - API 21 - API 21

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM