Android Spinner Underline color

后端 未结 3 1483
独厮守ぢ
独厮守ぢ 2020-12-06 06:25

I can add underline in spinner using style=\"@style/Base.Widget.AppCompat.Spinner.Underlined\". How can I change color of underline using style only? I dont wan

相关标签:
3条回答
  • 2020-12-06 06:47

    By default the Spinner will use the color set via android:textColorSecondary or colorControlNormal in your AppTheme. So either set the appropriate colors there or define a new Theme and apply this one to your Spinner:

    Example:

    styles.xml

    <style name="ThemeSpinner">
        <!-- Color when pressed -->
        <item name="colorAccent">#ffa000</item>
        <!-- Default color for the dropdown arrow and line -->
        <item name="colorControlNormal">#ffc107</item>
    </style>
    

    layout.xml

    <Spinner
        style="@style/Widget.AppCompat.Spinner.Underlined"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/ThemeSpinner" />
    

    Note: The dropdown arrow will also be tinted - I'm not aware of an option to color the arrow separately

    0 讨论(0)
  • 2020-12-06 06:55

    Add this to spinner

    android:backgroundTint="@color/gray"
    
    0 讨论(0)
  • 2020-12-06 07:03

    Seems like this question has already been answered. But here is a way to resolve that programatically as well. (Tested on API 19 & Above).

    Use ViewCompat for this.

    ViewCompat.setBackgroundTintList(spinner, ColorStateList.valueOf(your_color));
    
    0 讨论(0)
提交回复
热议问题