簡體   English   中英

Android 6.0+上的微調器背景不正確

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

我在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>

這里是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>

這里res\\drawable-mdpi\\spinner_pressed_custom.9.png

在此輸入圖像描述

這是Android 4.3的結果 在此輸入圖像描述

這里的結果是Android 6.0+ 在此輸入圖像描述

點擊微調器時: 在此輸入圖像描述

正如您所看到的,微調器的背景與Android 4.0不同。 在Android 4.0上。 是正確的微調器的背景。 但在android 6.0+中不正確。

這里結果九路發電機 在此輸入圖像描述

為什么?

在此輸入圖像描述 我認為它是dpi的問題,所以我建議你根據dpi制作9個補丁圖像

轉到下面的鏈接

點擊這里

並在此處拖動當前的9個補丁圖像,它將根據dpi生成圖像。

由於您沒有以編程方式設置漸變背景,因此問題僅在於棄用主題使用的樣式: Widget.Holo.Light.Spinner

只需將其替換為最新的主題,如Widget.AppCompat.Light.Spinner

此外,您可以嘗試更新targetSdkVersion並使用更新的SDK版本(如果這是您的選項)。

一些澄清:在較新的Android版本上打破漸變的實際原因是在dp中指定值的新要求,請參閱Lollipop上的Android Gradient無法正常工作。 - API 21

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM