0

I need to add an underline below my Spinner. From these links:

I have implemented the below:

In reminder_dialog_fragment.xml

<android.support.v7.widget.AppCompatSpinner
    android:id="@+id/spinner_1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    style="@style/Widget.AppCompat.Spinner.Underlined"
    android:theme="@style/MySpinnerTheme" />

In styles.xml

<style name="MySpinnerTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- set color for underline below Spinner -->
    <item name="colorControlActivated">#ffcfd8dc</item>
    <item name="colorControlHighlight">#ffcfd8dc</item>
    <item name="colorControlNormal">#ffcfd8dc</item>
</style>

I managed to display underline below Spinner & change the underline's color. But during spinner onclick / highlighted, there is some animation effect on Spinner:

  1. Ripple effect on the triangle (right side of Spinner)

  2. The underline below Spinner become bold

enter image description here

How can I remain the effect of (1), but disable the effect of (2)?

In other words, I want to prevent the underline become bold when Spinner is clicked.

Shuwn Yuan Tee
  • 5,578
  • 6
  • 28
  • 42

3 Answers3

0

may be you can try

 android:elevation="5dp"

in xml

BiRjU
  • 733
  • 6
  • 23
0

Try to use below code snippet for removing Spinner Bottomline color

    app:ms_basecolor="@android:color/transparent"
    app:ms_hightlightcolor="@android:color/transparent"

I hope it will work for you!

Nitin Karande
  • 1,280
  • 14
  • 33
0

There are multiple ways to do it. Try to give background as transparent.

<Spinner
  android:id="@+id/spTest"
  android:layout_margin="10dp"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:prompt="@string/spinner_prompt"
  android:background="@android:color/transparent"
  android:entries="@array/spinnerList"/>

Or create an EditText as shown in the code below:

<EditText
    android:id="@+id/etTest"
    android:layout_width="match_parent"
    android:layout_height="?actionBarSize"
    android:layout_margin="10dp"
    android:background="@drawable/edittext_rectangale_border"
    android:drawableEnd="@drawable/ic_arrow_drop"
    android:focusable="false"
    android:focusableInTouchMode="false"
    android:hint="@string/spinner_prompt"
    android:inputType="text"
    android:padding="5dp" />

You can find the drop_down_arrow from the vector asset. For the Border of EditText create a drawable named "edittext_rectangle_border.xml" and paste the below code in it.

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <solid android:color="#FFFFFF"/>
    <stroke
        android:width="3dp"
        android:color="#B9B9B9"/>
    <padding
        android:bottom="1dp"
        android:left="1dp"
        android:right="1dp"
        android:top="1dp"/>
    <corners
        android:bottomLeftRadius="3dp"
        android:bottomRightRadius="3dp"
        android:topLeftRadius="3dp"
        android:topRightRadius="3dp"/>
</shape>

After completing the above things, Open the java file and create a Dialog on EditText click by using onSetClickListner and display the list in the dialogbox. Later on selection of item set the EditText text.

Hope you find it useful.

Chirag Desai
  • 83
  • 1
  • 8