【问题标题】:Spinner background is not correct on Android 6.0+微调器背景在 Android 6.0+ 上不正确
【发布时间】:2018-09-05 08:55:43
【问题描述】:

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

我从这里安装 ADT:

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

在我的 manifest.xml 中

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

xml布局的sn-p:

  <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

Android 4.3 上的结果

这里是 Android 6.0+ 的结果

点击微调器时:

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

这里结果九路径生成器

为什么?

【问题讨论】:

  • 显示@drawable/spinner_default_custom 和其他人的代码
  • @AntonMalyshev "spinner_default_custom" 是 png 文件。这是右下角的黑色三角形
  • 看起来阴影渐变渲染不正确。这个看起来怎么样? spinner_selected_custom_border |另外,您发布的图片是从物理设备还是从 Eclipse 预览软件发布的?
  • @HedeH 如果我迁移到 Android Studio,这个问题会解决吗?
  • 应该和IDE无关,请发spinner_selected_custom_border

标签: android android-spinner


【解决方案1】:

我认为是dpi的问题,所以我建议你根据dpi制作9个补丁图像

转到下面的链接

Click Here

将你当前的9个patch图像拖到这里,它会根据dpi生成图像。

【讨论】:

  • 没用。结果相同。
  • 预览模块中显示的结果图你拖了吗?
  • 是的,我下载 zip 并将其解压缩到“res”文件夹。
  • 我已经更新了截图,你的观点和截图上的预览部分相似吗?
  • 我更新了我的帖子。不,我的预览和你的预览不同。
【解决方案2】:

由于您没有以编程方式设置渐变背景,因此问题出在已弃用主题中使用的样式:Widget.Holo.Light.Spinner

只需将其替换为Widget.AppCompat.Light.Spinner 等最新主题即可。

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

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

【讨论】:

  • 我收到错误:检索项目的父项时出错:找不到与给定名称“@android:style/Widget.AppCompat.Light.Spinner”匹配的资源
  • 如果我使用这个:parent="Widget.AppCompat.Spinner" 那么我会得到同样的错误。微调器的背景不正确。
  • 那么可能唯一的办法就是更新使用的 Android SDK 版本
猜你喜欢
  • 1970-01-01
  • 2016-06-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-06-26
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多