How to customize a spinner on android

2

I want to customize a spinner, or create it if there is no case, that has a style like this:

What form can it be made of? At the moment I just managed to create an XML that has the bottom of the spinner, but I do not know how to add the arrow. To assign it I did it from the Background property of the spinner, and here the code:

<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<solid android:color="#bdfbea"/>

<stroke android:width="3dp"
    android:color="#00887b"/>

<padding android:left="1dp"
    android:top="1dp"
    android:right="1dp"
    android:bottom="1dp"/>

<corners android:radius="50dp"/>

    
asked by LcsGrz 18.07.2018 в 19:41
source

1 answer

3

spinner_style.xml

Add another item and within it a bitmap and you pass your ic_arrow.png in this case:

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

                    <stroke android:width="3dp" android:color="#00887b" />

                    <padding android:bottom="1dp" android:left="1dp" android:right="1dp" android:top="1dp" />

                    <corners android:radius="50dp" />
                </shape>
            </item>
            <item>

                <bitmap android:gravity="bottom|right"
                    android:src="@drawable/ic_arrow">
                </bitmap>

            </item>
        </layer-list>
    </item>

</selector>

acitity.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <Spinner
        android:background="@drawable/spinner_style"
        android:layout_width="150dp"
        android:layout_height="wrap_content"
       />


</android.support.constraint.ConstraintLayout>

To play with the oritacion of the image you can use this

   <bitmap android:**gravity="center|right"**
                    android:src="@drawable/ic_arrow">
                </bitmap>


 <bitmap android:**gravity="center|left"**
                    android:src="@drawable/ic_arrow">
                </bitmap>
    
answered by 18.07.2018 / 21:43
source