Android Support Toolbar colorControlNormal color

后端 未结 2 740
無奈伤痛
無奈伤痛 2020-12-28 15:51

I would like to set my spinner drop down color to white, whilst keeping the other elements in my theme the default color. Here is the situation:

相关标签:
2条回答
  • 2020-12-28 16:31

    Finally, I have found a solution on how to change arrow color of Spinner to white.

    1) In styles.xml, add the following style:

    <style name="ActionBarThemeOverlay" parent="">
        <item name="android:textColorPrimary">#ffffff</item>
        <item name="colorControlNormal">#ffffff</item>
        <item name="colorControlHighlight">#ff33b5e5</item>
    </style>
    
    <style name="Widget.MyTheme.HeaderBar.Spinner" parent="Widget.AppCompat.Light.Spinner.DropDown.ActionBar">
        <item name="android:theme">@style/ActionBarThemeOverlay</item>
    </style>
    

    2) In the layout, where you use the Spinner (in your case with Toolbar), add the style to your spinner:

    <Spinner
        xmlns:android="http://schemas.android.com/apk/res/android"
             android:id="@+id/my_spinner"
             style="@style/Widget.MyTheme.HeaderBar.Spinner"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content" />
    
    0 讨论(0)
  • 2020-12-28 16:36

    Just stumbled across this questions. Even though it has been asked some time ago I just wanted to leave an answer that should work:

    Toolbar *.xml

    <android.support.v7.widget.Toolbar
        <!-- leave the theme stuff out of here -->
        style="@style/MyToolbarStyle"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
    

    Styles / Themes

    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <!-- your other attributes -->
        <!-- following is used to tint the checkbox - purple for demo purpose -->
        <item name="colorControlNormal">#2196F3</item>
    </style>
    
    <style name="MyToolbarStyle">
        <item name="android:minHeight">?actionBarSize</item>
        <item name="android:background">?colorPrimary</item>
        <item name="popupTheme">@style/ThemeOverlay.AppCompat.Light</item>
        <item name="theme">@style/MyToolbarTheme</item>
    </style>
    
    <style name="MyToolbarTheme">
        <!-- Used to tint the back arrow, menu and spinner arrow -->
        <item name="colorControlNormal">#FFF</item>
    </style>
    

    Result

    solution with different colors for spinner and checkbox

    Note: I made the checkbox purple for demo purpose

    0 讨论(0)
提交回复
热议问题