How to add a line at the bottom of spinner as like edittext in android

前端 未结 6 1867
时光说笑
时光说笑 2021-02-02 06:39

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

相关标签:
6条回答
  • 2021-02-02 06:41

    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

    0 讨论(0)
  • 2021-02-02 06:47

    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>
    

    0 讨论(0)
  • 2021-02-02 06:53

    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"
                        />
    
    0 讨论(0)
  • 2021-02-02 06:54

    I just faced the same Problem and after researching for a while the answer is quite easy:

        <Spinner
            ...            
            style="@style/Widget.AppCompat.Spinner.Underlined"
            ... />
    
    0 讨论(0)
  • 2021-02-02 06:57

    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.

    0 讨论(0)
  • 2021-02-02 07:07
    <android.support.v7.widget.AppCompatSpinner
            ...            
            style="@style/Widget.AppCompat.Spinner.Underlined"
            app:backgroundTint="YOUR_COLOR_HERE"
            ... />
    
    0 讨论(0)
提交回复
热议问题