Hello I am making demo application in which i am using EditText
in which a line appears at the bottom that is ok but it is not in case of spinner.
How this
Its Working
<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">#3F51B5</item>
</style>
Happy Coding
Since no one has posted an actual answer, here ya go:
<item android:bottom="1dp"
android:left="-2dp"
android:right="-2dp"
android:top="-2dp">
<shape android:shape="rectangle" >
<stroke
android:width="0.5dp"
android:color="@android:color/black" />
</shape>
</item>
If @style/Widget.AppCompat.Spinner.Underlined
not found or not Working used below style
to spinner for bottom Underlined
<Spinner
android:id="@+id/spinner"
android:layout_width="wrap_content"
style="@android:style/Widget.Material.Spinner.Underlined"
android:layout_height="wrap_content"
/>
I just faced the same Problem and after researching for a while the answer is quite easy:
<Spinner
...
style="@style/Widget.AppCompat.Spinner.Underlined"
... />
That line is what you write your input above. A spinner doesn't have that line because it is not a text input field. If you want to have a line below the spinner too, You could insert it below by faking it like this:
<Spinner
android:id="@+id/firstSpinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:hint="@string/firstHint" />
<!-- Separator view -->
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@android:color/black"/>
<Spinner
android:id="@+id/secondSpinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:hint="@string/secondHint" />
<!-- Insert separator view again-->
Probably you need to play around with the margins a bit. Also notice that the black line is only in Android 5.0, and the whole layout will look a lot different on older Androids. If you only want to have to black line on Android 5.0, then you have to make a copy of the layout, and insert it in a directory called layout-v21
, and have the other version in the default layout
directory.
<android.support.v7.widget.AppCompatSpinner
...
style="@style/Widget.AppCompat.Spinner.Underlined"
app:backgroundTint="YOUR_COLOR_HERE"
... />