Spinner does not apply dropDownSelector attribute

前端 未结 3 1739
花落未央
花落未央 2020-12-17 17:05

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

相关标签:
3条回答
  • 2020-12-17 17:40

    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!

    0 讨论(0)
  • 2020-12-17 17:43

    There may be other ways but here's what I understand from using one of the Generators.

    Declare your own style for the spinner in your res/values/styles.xml pointing to your drawable.

    <style name="myCustomSpinner" parent="android:Widget.Holo.Light.Spinner">
        <item name="android:background">@drawable/spinner_state</item>
    </style>
    

    Create res/values/themes.xml and declare your own theme that inherits from the current theme. Within this theme, add an item for each attribute you're modifying and point it to your custom style from the last step. I think this could go in the styles file if you wanted, but since the generator separates them I follow suit.

    <style name="myCustomTheme" parent="android:Theme.Light">
        <item name="android:dropDownSpinnerStyle">@style/myCustomSpinner</item>
    </style>
    

    In your AndroidManifest, add android:theme="@style/myCustomTheme" to the opening application tag.

    Your values for parent will depend on how the project is setup and I think this will style of the spinners in your project and not just one. Try it out and let me know what you get.

    0 讨论(0)
  • 2020-12-17 17:55
    <?xml version="1.0" encoding="utf-8"?>
    <selector xmlns:android="http://schemas.android.com/apk/res/android">
        <item android:state_focused="true" android:drawable="@color/lighter_gray_no_transparent" />
        <item android:state_selected="true" android:drawable="@color/lighter_gray_no_transparent" />
        <item android:state_pressed="true" android:drawable="@color/lighter_gray_no_transparent" />
        <item android:drawable="@android:color/transparent"/>
    </selector>
    
    <color name="lighter_gray_no_transparent">#FFDDDDDD</color>
    

    set backgroud selector for your item view, that's all. Work for me. The color alpha value should be FF, or it will show orange background, left one color value is #FFDDDDDD, the right one is #55DDDDDD

    enter image description here enter image description here

    0 讨论(0)
提交回复
热议问题