How to set the down arrow to a background spinner?

I have a dropdown with black background, blue spinner outline, How do I put an arrow image in the dropdown?

I use

Android: background = "@ android: draw / btn _dropdown"

but this will remove my current background i.e. black background with blue outline. For this I am using drawable

<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape= "rectangle"  >
    <solid android:color="#000000"/>
    <stroke android:width="2dp"  android:color="#405999"/>
</shape>

      

+3


source to share


1 answer


You can try this,

Create a file spinner_bg.xml

in a portable folder then copy and paste the following

spinner_bg.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="@drawable/spinner_ab_default_holo_dark_am" />
            </item>
        </layer-list></item>

</selector>  

      



Inside the folder values

and styles.xml

add these lines

<style name="spinner_style" >
            <item name="android:background">@drawable/spinner_bg</item>
            <item name="android:layout_marginLeft">10dp</item>
            <item name="android:layout_marginRight">10dp</item>
            <item name="android:layout_marginBottom">10dp</item>
            <item name="android:paddingLeft">8dp</item>
            <item name="android:paddingTop">5dp</item>
            <item name="android:paddingBottom">5dp</item>

        </style>

      

Add this style to your spinner in xml file

       <Spinner
            android:id="@+id/spinner1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            style="@style/spinner_style"
            android:popupBackground="#cccccc" />

      

+9


source







All Articles