I\'m using android spinner and edittext from support lib v21. I would like to align text to left the same like edittext as shown in figure. But, deafult spinner include spac
You can also remove the padding of spinner in xml
Only need to set padding to 0dp.
<Spinner
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:padding="0dp"
android:id="@+id/my_spinner">
If yo don't want to mess in Java Code and have it in styles
Search for this file (Cmd+Shift+O)
abc_spinner_textfield_background_material.xml
and copy to your project. Remove all inset values from root element and refer the file as background of your spinner.
In my case it looks like this (drawable/spinner_background.xml
)
<inset xmlns:android="http://schemas.android.com/apk/res/android">
<selector>
<item
android:state_checked="false"
android:state_pressed="false">
<layer-list>
<item android:drawable="@drawable/abc_textfield_default_mtrl_alpha" />
<item android:drawable="@drawable/abc_spinner_mtrl_am_alpha" />
</layer-list>
</item>
<item>
<layer-list>
<item android:drawable="@drawable/abc_textfield_activated_mtrl_alpha" />
<item android:drawable="@drawable/abc_spinner_mtrl_am_alpha" />
</layer-list>
</item>
</selector>
</inset>
and in my styles.xml I use it this way
<style name="DxSpinner" parent="@style/Widget.AppCompat.Spinner.Underlined">
<item name="android:background">@drawable/spinner_background</item>
</style>