Android Spinner border issue

I have make the spinner he work perfect but the design issue. My Spinner code is

<Spinner
        android:id="@+id/product"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:drawable="@drawable/border"
        android:padding="25dp">
    </Spinner>

Java code

spinnerShop = (Spinner) myView.findViewById(R.id.shop);
/*Shop Spinner*/
ArrayAdapter<CharSequence> shopArray = ArrayAdapter.createFromResource(getActivity(),
        R.array.shopArray, android.R.layout.simple_list_item_1);
shopArray.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinnerShop.setAdapter(shopArray);

@drawable/border code

    <shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
<corners
    android:radius="2dp" />
<solid android:color="@color/colorText" />
<stroke
        android:width="1dip"
        android:color="@color/colorPrimary"/>
</shape>

Border not shown arround the spinner Show the image enter image description here

2 answers

  • answered 2017-06-17 18:47 Gil Goldzweig

    <Spinner
        android:id="@+id/product"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:drawable="@drawable/border" // replace this line
        android:background="@drawable/border" // with this
        android:padding="25dp">
    </Spinner>
    

  • answered 2017-06-17 18:47 CanDroid

    You need to define a custom style on your style.xml file for your spinner. Then you will give this custom style to your spinner as below:

    <Spinner
        android:id="@+id/product"
        style="@style/your_custom_spinner_style" 
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="25dp"/>
    

    You will use your @drawable/border_code in your_custom_spinner_style in style.xml file as below:

    <style name="your_custom_spinner_style">          
              <item name="android:background">@drawable/border_code</item>
              ........
         </style>
    

    Please inform me after you try it.