Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create custom spinner like border around the spinner with down triangle on the right side?

I want to develop custom spinner like line around spinner with triangle at right bottom corner.
like following image

enter image description here

For above fig I wrote my custom spinner like a

spinner.xml

 <Spinner android:background="@drawable/spinner_background"/> 

spinner_background.xml

<?xml version="1.0" encoding="UTF-8"?> 

<item android:state_pressed="true"       android:drawable="@drawable/spinner_ab_pressed_new_theme_bs">     <shape>          <solid              android:color="@color/White" />          <corners android:radius="3dp" />          <padding              android:bottom="10dp"              android:left="10dp"              android:right="10dp"              android:top="10dp" />           <stroke              android:width="2dp"              android:color="@color/skyblue" />     </shape>  </item>  <!-- spinner_ab_default_new_theme_bs -> this image for corner triangle --> <item      android:drawable="@drawable/spinner_ab_default_new_theme_bs" >     <shape>         <solid             android:color="@color/White">         </solid>          <corners android:radius="3dp" />          <padding             android:bottom="10dp"              android:left="10dp"              android:right="10dp"              android:top="10dp" />          <stroke              android:width="2dp"              android:color="@color/gray"/>     </shape> </item> 

And I got output like following image
enter image description here

I tried lot but not achieve my goal please anybody have solution to develop spinner.
like above first one image.

like image 220
nilesh wani Avatar asked Jun 21 '13 09:06

nilesh wani


People also ask

What is spinner in Android with example?

Android Spinner is a view similar to the dropdown list which is used to select one option from the list of options. It provides an easy way to select one item from the list of items and it shows a dropdown list of all values when we click on it.

What is a spinner Android studio?

Spinners provide a quick way to select one value from a set. In the default state, a spinner shows its currently selected value. Touching the spinner displays a dropdown menu with all other available values, from which the user can select a new one. You can add a spinner to your layout with the Spinner object.


1 Answers

Spinner

<Spinner     android:id="@+id/To_Units"     style="@style/spinner_style" /> 

style.xml

    <style name="spinner_style">           <item name="android:layout_width">match_parent</item>           <item name="android:layout_height">wrap_content</item>           <item name="android:background">@drawable/gradient_spinner</item>           <item name="android:layout_margin">10dp</item>           <item name="android:paddingLeft">8dp</item>           <item name="android:paddingRight">20dp</item>           <item name="android:paddingTop">5dp</item>           <item name="android:paddingBottom">5dp</item>           <item name="android:popupBackground">#DFFFFFFF</item>      </style> 

gradient_spinner.xml (in drawable folder)

<?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="#B3BBCC" android:startColor="#E8EBEF" android:type="linear" />                      <stroke android:width="1dp" android:color="#000000" />                      <corners android:radius="4dp" />                      <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_arrow" />             </item>         </layer-list></item>  </selector>   

@drawable/spinner_arrow is your bottom right corner image

like image 155
Samadhan Medge Avatar answered Oct 11 '22 22:10

Samadhan Medge