Spinner Dropdown Arrow

后端 未结 2 1506
太阳男子
太阳男子 2020-12-19 10:28

I am trying to obtain a custom Spinner such as this one:

\"\"

but I was only able to get this:

相关标签:
2条回答
  • 2020-12-19 10:59

    You have to remove the Imageview into your custom layout row_spinner.xml. In case, you don't need to create an arrow inside your custom layout, because if you do, it'll be created in each row like happened to you. For doing the same you showed us, you must change the Spinner style into your styles.xml.

    For example:

    <resources>
    
        <style name="SpinnerTheme" parent="android:Widget.Spinner">
            <item name="android:background">@drawable/spinner_background_holo_light</item>
            <item name="android:dropDownSelector">@drawable/list_selector_holo_light</item>
        </style>
    
        <style name="SpinnerTheme.DropDown">
            <item name="android:spinnerMode">dropdown</item>
        </style>
    
        <!-- Changes the spinner drop down item radio button style -->
        <style name="DropDownItemSpinnerTheme" parent="android:Widget.DropDownItem.Spinner">
            <item name="android:checkMark">@drawable/btn_radio_holo_light</item>
        </style>
    
        <style name="ListViewSpinnerTheme" parent="android:Widget.ListView">
            <item name="android:listSelector">@drawable/list_selector_holo_light</item>
        </style>
    
        <style name="ListViewSpinnerTheme.White" parent="android:Widget.ListView.White">
            <item name="android:listSelector">@drawable/list_selector_holo_light</item>
        </style>
    
        <style name="SpinnerItemTheme" 
                parent="android:TextAppearance.Widget.TextView.SpinnerItem">
            <item name="android:textColor">#000000</item>
        </style>
    
    </resources>
    

    For further information take a look: http://androidopentutorials.com/android-how-to-get-holo-spinner-theme-in-android-2-x/

    EDIT

    selector_spinner.xml:

    <?xml version="1.0" encoding="utf-8"?>
    <selector xmlns:android="http://schemas.android.com/apk/res/android">
    
        <item>
    
            <layer-list>
    
                <item>
                    <shape>
                        <gradient android:angle="90" android:endColor="#ffffff" android:startColor="#ffffff" android:type="linear" />
    
                        <stroke android:width="1dp" android:color="#504a4b" />
    
                        <corners android:radius="5dp" />
    
                        <padding android:bottom="3dp" android:left="3dp" android:right="3dp" android:top="3dp" />
                    </shape>
                </item>
    
                <item>
    
                    <bitmap android:gravity="bottom|right" android:src="@android:drawable/arrow_up_float" />
    
                </item>
    
            </layer-list>
    
        </item>
    
    </selector>
    

    styles.xml:

    <resources>
    
        <!-- Base application theme. -->
        <style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
            <item name="android:spinnerStyle">@style/SpinnerTheme</item>
        </style>
    
        <style name="SpinnerTheme" parent="android:Widget.Spinner">
            <item name="android:background">@drawable/selector_spinner</item>
        </style>
    
    </resources>
    

    At the end, the spinner will look like as enter image description here

    EDIT 2

    The following code is into details_fragment_three.xml

    <Spinner
        android:id="@+id/spinnerDate"
        android:layout_marginLeft="-8dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/spinner_item_drawable"/> 
    
    0 讨论(0)
  • 2020-12-19 11:03

    You can use your own drop down image;

            <item>
    
                <layer-list>
    
                    <item>
                        <color android:color="@android:color/white" />
                    </item>
    
                    <item>
                        <bitmap android:gravity="center_vertical|right" android:src="@drawable/down_arrow" /> // down_arrow replace your image
                    </item>
    
                </layer-list>
    
            </item>
    
        </selector>
    
    0 讨论(0)
提交回复
热议问题