How to create android spinner without down triangle on the right side of the widget with bottom line

笑着哭i 提交于 2020-01-07 03:15:19

问题


I want to remove down triangle on the right side and wants to bottom line. I am using following code to add bottom line:

<Spinner
android:id="@+id/buttonSelectCountry"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:gravity="center"
android:spinnerMode="dropdown"
android:text="Select country"
style="@style/Widget.AppCompat.Spinner.Underlined"/>

and following code to remove down arrow:

<Spinner
android:id="@+id/buttonSelectCountry"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:gravity="center"
android:spinnerMode="dropdown"
android:text="Select country"
style="@style/Widget.AppCompat.Spinner.Underlined"
android:background="#FFFFFF"/>

But using above code the bottom line also gets invisible.

How can I do this.


回答1:


<?xml version="1.0" encoding="utf-8"?>
 <selector xmlns:android="http://schemas.android.com/apk/res/android">
   <item>
    <layer-list>
        <item>
            <shape >
                <corners android:radius="5dp" />
                <!--<padding android:bottom="3dp" android:left="3dp" android:right="3dp" android:top="3dp" />-->
                <solid android:color="@color/bgcolor"/>
            </shape>
        </item>
        <item>
            <bitmap android:gravity="bottom|center" android:src="@drawable/ninepatchline" />
        </item>
    </layer-list>
  </item>
</selector> 

Set this drawable as Background of the spinner

UPDATE

Add paddingBottom to spinner.

android:paddingBottom="@dimen/min_padding"




回答2:


You can use a custom background in drawable folder which have a bottom line in it.

bottom_line.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape>
            <solid
                android:color="#000000" />
            <padding
                android:bottom="1dp" />
        </shape>
    </item>
    <item>
        <shape>

            <solid android:color="#FFFFFF"/>
        </shape>
    </item>
</layer-list>

put this as your background to spinner :

<Spinner
    android:id="@+id/buttonSelectCountry"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:layout_centerHorizontal="true"
    android:spinnerMode="dropdown"
    android:text="Select country"
    android:background="@drawable/bottom_line"/>



回答3:


You can simply add background to your spinner. if your main background is white than you can simply set your spinner background as follow with white color code or any relevant color code you want that matches your main background.

<Spinner
android:id="@+id/buttonSelectCountry"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:gravity="center"
android:text="Select country"
android:background="#FFFFFF"/>

Replace this code with yours.



来源:https://stackoverflow.com/questions/41013678/how-to-create-android-spinner-without-down-triangle-on-the-right-side-of-the-wid

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!