I am using a appcompat theme for my application. Need to know how i can show underline to spinner. It is just showing anchor. I tried setting up underline using android:background but it makes the anchor disappear.
4 Answers
Update your support library and in XML use
Please add this style to your Spinner
style="@style/Base.Widget.AppCompat.Spinner.Underlined"

- 6,040
- 7
- 52
- 85

- 3,203
- 4
- 19
- 41
-
10How to color the underline ? – rohitsakala Jul 11 '15 at 17:56
-
3Any way to remove the drop down arrow and have it underlined ? if I set any background, the underline disappears. – Vineet Ashtekar Feb 07 '16 at 03:55
-
Any solutions to above ? If I use this style, my arrow is replaced by the default one. – AndroidGuy Mar 16 '17 at 10:40
-
3`android:backgroundTint="@color/your_color"` – Vaibhav Jani Dec 03 '18 at 09:21
-
For Android X: `style="@style//Widget.Material.Spinner.Underlined"` – notes-jj Oct 20 '20 at 20:36
-
How to reduce the height between spinner - textView and underline – RaJ Aug 25 '22 at 09:47
-
@RaJ you can set the paddingBottom to the desired value. – David Rauca Jun 13 '23 at 09:51
This is hacky (and not perfect) way to change spinner and underline color in appcompat theme. Main point that I customized Android support library images and xml files to change color.
1) go to support library package and copy 2 images (or download my custom from the bottom of this post)
/your-app/build/intermediates/exploded-aar/com.android.support/appcompat-v7/23.1.0/res/drawable-hdpi/abc_spinner_mtrl_am_alpha.9.png
and
/your-app/build/intermediates/exploded-aar/com.android.support/appcompat-v7/23.1.0/res/drawable-hdpi/abc_textfield_default_mtrl_alpha.9.png
2) Make a copy of those images
3) Change color of abc_spinner_mtrl_am_alpha.9.png (warning: leave black borders as they are, it's for 9 patch)
4) Change color of second bottom line of abc_textfield_default_mtrl_alpha.9.png (you can see in attached small image below)
5) Save and move files to your project drawables
6) Create bottom_line_color.xml drawable:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:top="-6dp" android:left="-6dp" android:right="-6dp">
<shape>
<stroke android:color="@color/brown" android:width="6dp"/>
</shape>
</item>
7) Create spinner_bottom_line.xml
<?xml version="1.0" encoding="utf-8"?>
<inset xmlns:android="http://schemas.android.com/apk/res/android"
android:insetLeft="@dimen/abc_control_inset_material"
android:insetTop="@dimen/abc_control_inset_material"
android:insetBottom="@dimen/abc_control_inset_material"
android:insetRight="@dimen/abc_control_inset_material">
<selector>
<item android:state_checked="false" android:state_pressed="false">
<layer-list>
<item android:drawable="@drawable/my_custom_abc_textfield_default_mtrl_alpha" />
<item android:drawable="@drawable/my_custom_abc_spinner_mtrl_am_alpha" />
</layer-list>
</item>
<item>
<layer-list>
<item android:drawable="@drawable/my_custom_abc_textfield_default_mtrl_alpha" />
<item android:drawable="@drawable/my_custom_abc_spinner_mtrl_am_alpha" />
</layer-list>
</item>
</selector>
</inset>
P.S. I couldn't achieve same visual style as default spinner (visual changes shown below). If you start using this custom spinner theme you should use it in all project.
So add to values/styles.xml
<style name="My.Spinner.Style" parent="Base.Widget.AppCompat.Spinner.Underlined">
<item name="android:background">@drawable/spinner_bottom_line</item>
</style>
And use it in application like this:
<Spinner
android:id="@+id/account_spinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/My.Spinner.Style"
/>
Important: You should resize spinner and place to various drawables folders. You can find size in same path as I showed above. There are few popular sizes:
drawables-mdpi 20x26
drawables-hdpi 29x38
drawables-xhdpi 38x50
drawables-xxhdpi 74x98
You can take my customized images from here:
my_custom_abc_spinner_mtrl_am_alpha:
my_custom_abc_textfield_default_mtrl_alpha:
Spinner example is (xxhdpi), line is mdpi (because we don't need various lines in various drawable folders, so we can have only 1).
Visual difference (from android studio xml preview window) is shown here:
First line is my custom underline spinner, second is default Base.Widget.AppCompat.Spinner.Underlined

- 2,700
- 1
- 26
- 41
-
my friend your method might be correct but if android it self provides a single line using which you can achieve this why to do so much of hard work? – Pritam Kadam Nov 04 '15 at 10:47
-
2I did not find the way to change the spinner underline color. If i changed background in styles.xml spinner item disappeared. So this solution helps me to change bottom line color and leave spinner item – Ragaisis Nov 04 '15 at 10:49
-
An interesting solution. I found it easier to place an imageview (with my line) below my spinner. – Yar May 19 '16 at 18:15
-
I've tried your solution, but for me the arrow is displayed on the left. Do you know why? – Ionut Negru Aug 12 '16 at 08:48
-
Applying style="@style/Base.Widget.AppCompat.Spinner.Underlined"
didn't show any difference .Then gave android:backgroundTint
and android:backgroundTintMode
to spinner and it worked.
<Spinner
android:id="@+id/spBookingType"
android:spinnerMode="dropdown"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/Base.Widget.AppCompat.Spinner.Underlined"
android:backgroundTint="#ff000000"
android:backgroundTintMode="src_in" />

- 13,845
- 13
- 50
- 77

- 449
- 6
- 18
in styles.xml
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:spinnerStyle">@style/holoSpinner</item>
</style>
<style name="holoSpinner" parent="Widget.AppCompat.Spinner.Underlined">
<item name="android:textSize">16sp</item>
<item name="android:textColor">@color/colorPrimary</item>
</style>
========================
in Layout
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp">
<Spinner
android:id="@+id/spinCountry"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/edit_text_bottom_border"
android:paddingBottom="10dp" />
</android.support.design.widget.TextInputLayout>
===============================================
edit_text_bottom_border.xml file in Drawable
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:bottom="1dp"
android:left="-3dp"
android:right="-3dp"
android:top="-3dp">
<shape android:shape="rectangle">
<stroke
android:width="1dp"
android:color="#535353" />
<!--android:color="#535353" />-->
</shape>
</item>
</layer-list>

- 10,807
- 1
- 75
- 53