Change Spinner dropdown icon

后端 未结 9 2164
旧巷少年郎
旧巷少年郎 2020-12-12 14:07

The solutions I found to change the spinner dropdown icon where all:

1. create a custom drawable



        
相关标签:
9条回答
  • 2020-12-12 15:10

    For this you can use .9 Patch Image and just simply set it in to background.

    android:background="@drawable/spin"
    

    Here i'll give you .9patch image. try with this.

    Right click on image and click Save Image as

    set image name like this : anyname.9.png and hit save.

    Enjoy.. Happy Coading. :)

    0 讨论(0)
  • 2020-12-12 15:10

    You need to create custom background like this:

    <?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="@drawable/drop_down"/> // you can place your dropdown image
                </item>
            </layer-list>
        </item>
    
    </selector>
    

    Then create style for spinner like this:

    <style name="spinner_style">
            <item name="android:background">@drawable/YOURCUSTOMBACKGROUND</item>
            <item name="android:layout_marginLeft">5dp</item>
            <item name="android:layout_marginRight">5dp</item>
            <item name="android:layout_marginBottom">5dp</item>
    </style>
    

    after that apply this style to your spinner

    0 讨论(0)
  • 2020-12-12 15:13

    Have you tried to define a custom background in xml? decreasing the Spinner background width which is doing your arrow look like that.

    Define a layer-list with a rectangle background and your custom arrow icon:

        <?xml version="1.0" encoding="utf-8"?>
    <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
        <item>
            <shape android:shape="rectangle">
                <solid android:color="@color/color_white" />
                <corners android:radius="2.5dp" />
            </shape>
        </item>
        <item android:right="64dp">
             <bitmap android:gravity="right|center_vertical"  
                 android:src="@drawable/custom_spinner_icon">
             </bitmap>
        </item>
    </layer-list>
    
    0 讨论(0)
提交回复
热议问题