Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
439 views
in Technique[技术] by (71.8m points)

android - Spinner does not apply dropDownSelector attribute

I'm using spinner and want to add spinner - to change behavior depends of states(focused, pressed)

sample project is here https://github.com/vovs/spinner_issue

My code:

activity_main.xml

<Spinner
        android:id="@+id/spinner"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="30dp"
        android:spinnerMode="dropdown"
        android:dropDownSelector="@drawable/spinner_state" />

spinner_state.xml

<?xml version="1.0" encoding="utf-8"?>

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:state_enabled="false"
        android:drawable="@color/black" />
    <item
        android:state_pressed="true"
        android:state_enabled="true"
        android:drawable="@color/red" />
    <item
        android:state_focused="true"
        android:state_enabled="true"
        android:drawable="@color/red" />
    <item
        android:state_enabled="true"
        android:drawable="@color/gray" />
</selector>

AndroidManifest:

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

So, if I run app in emulator Android 4.0.2 API 14 and try to select some item or scroll using wheel of my mouse no any effect, that I set in selector(when press or scrolling - items should be red, but it is blue - default for ICS color).

For Android 2.2 API 8 when press or scroll using wheel(in this case state is focused) color is yellow[orange](default color for Android 2.2)

How to enable selector for spinner?

enter image description here

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

also an official bug... https://code.google.com/p/android/issues/detail?id=24922

what helps:

<resources>
    <style name="Theme.MyTheme" parent="@android:style/Theme.Holo.Light">
        <item name="android:dropDownListViewStyle">@style/Theme.MyListView</item>
    </style>

    <style name="Theme.MyListView" parent="@android:style/Widget.Holo.Light.ListView">
        <item name="android:listSelector">@drawable/orange_list</item>
    </style>
</resources>

good luck!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...