Friday, 28 June 2019

Android Spinner background customize using xml Selector

Here sharing to customize background design of Spinner item  with costume xml file to put in resource drawable  folder and set it in xml Spinner item.

create this xml file in res/drawable folder with name spinner_background.xml
do code for it like as below


<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item >
      <layer-list>
        <item>
          <shape>
            <stroke android:width="1dp" android:color="#dddddd" />
            <padding  android:bottom="3dp" android:left="3dp" android:right="3dp" android:top="3dp"/>
            <solid android:color="#FFFFFF" />
        </shape>
       </item>
        <item ><bitmap android:gravity="right|center" android:src="@mipmap/ic_downarrow" />
        </item>
    </layer-list></item>
</selector>


here you need to set ic_downarrow image in mipmap folder as per you need design. will look in Spinner 
right side this image.


Now in your layout,xml file with Spinner item do set this xml file to display costume spinner background 



<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">

    <Spinner
        android:id="@+id/spnitem"
        android:layout_width="200dp"
        android:layout_gravity="center_horizontal"
        android:layout_height="@dimen/editext_size"
        android:overlapAnchor="false"
        android:textSize="@dimen/reg_text_size"
        android:background="@drawable/spinner_background"        />

</LinearLayout> 

No comments:

Post a Comment

Comments

Find Hours Diffrence in Kotlin

  In Kotlin, determining the difference in hours between two timestamps is a common task, especially in scenarios involving time-based calcu...