我在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
如您所见,微调框的背景与Android 4.0不同。在android 4.0上。是正确的微调器背景。但是在android 6.0+中是不正确的。
为什么?
答案 0 :(得分:0)
答案 1 :(得分:0)
由于您不是通过编程方式设置渐变背景,所以问题就出在已弃用主题中使用的样式:Widget.Holo.Light.Spinner
。
只需将其替换为最新主题,例如Widget.AppCompat.Light.Spinner
。
如果您可以选择的话,也可以尝试更新targetSdkVersion
并使用更新的SDK版本。
一些澄清: 在新的Android版本上渐变被破坏的真正原因是在dp中指定值的新要求,请参见Android Gradient on Lollipop not working. - API 21