• Custom Spinner background with border XML

    Make your spinner border and background like below image:
    • Create an android project.
    • Open activity_main.xml layout file
    • Add a spinner to your activity_main.xml
    1. <?xml version="1.0" encoding="utf-8"?>
    2. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    3. xmlns:app="http://schemas.android.com/apk/res-auto"
    4. xmlns:tools="http://schemas.android.com/tools"
    5. android:layout_width="match_parent"
    6. android:layout_height="match_parent"
    7. tools:context="com.shohoz.checkjsonparsing.MainActivity">
    8. <Spinner
    9. android:id="@+id/spinner"
    10. android:layout_width="match_parent"
    11. android:layout_height="wrap_content"/>
    12. </RelativeLayout>
    • Now Download this image   
    • Put downloaded image to drawable folder.
    • then create a xml file in your  drawable folder like spinner_border.xml, now copy the below code:
    1. <?xml version="1.0" encoding="utf-8"?>
    2. <selector xmlns:android="http://schemas.android.com/apk/res/android">
    3. <item><layer-list>
    4. <item><shape>
    5. <stroke android:width="2dp" android:color="#f58218" />
    6. <padding android:bottom="3dp" android:left="3dp" android:right="3dp" android:top="3dp" />
    7. </shape></item>
    8. <item ><bitmap android:gravity="right|center" android:src="@drawable/ic_spinner" />
    9. </item>
    10. </layer-list></item>
    11. </selector>

    • Now go to your spinner then set background
    1. <?xml version="1.0" encoding="utf-8"?>
    2. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    3. xmlns:app="http://schemas.android.com/apk/res-auto"
    4. xmlns:tools="http://schemas.android.com/tools"
    5. android:layout_width="match_parent"
    6. android:layout_height="match_parent"
    7. tools:context="com.shohoz.checkjsonparsing.MainActivity">
    8. <Spinner
    9. android:id="@+id/spinner"
    10. android:layout_width="match_parent"
    11. android:layout_height="wrap_content"
    12. android:background="@drawable/spinner_border"/>
    13. </RelativeLayout>
  • 5 comments:

    FAVOURITE LINE

    To steal ideas from one is plagiarism. To steal from many is Research.

    ADDRESS

    Mumbai , Maharashtra

    EMAIL

    shikha.pathak6@gmail.com
    shikha.the.swt.pari@gmail.com

    Skype

    shikha_pari