Search code examples
androidandroid-layoutandroid-actionbarandroid-toolbarandroid-button

making action buttons of the ActionBar white


I want to make the color of action buttons of the ActionBar android.support.v7.widget.Toolbar, white. I don't want to use a custom resource. I know when i use DarkTheme, the buttons automatically turns to white but i am using a transparent ActionBar and i don't want to increase overhead by adding new resources to my application.

I was able to do this easily for the arrow button in DrawerLayout by using

<style name="DrawerArrowStyle" parent="Widget.AppCompat.DrawerArrowToggle"> <item name="color">@android:color/white</item> </style>


Solution

  • You can use a Toolbar defining the theme and the style:

    <android.support.v7.widget.Toolbar
            xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:app="http://schemas.android.com/apk/res-auto"
            style="@style/HeaderBar"
            app:theme="@style/ActionBarThemeOverlay"
            app:popupTheme="@style/ActionBarPopupThemeOverlay"/>
    

    And you can have the full control of your ui elements with these styles:

     <style name="ActionBarThemeOverlay" parent="">
         <item name="android:textColorPrimary">#fff</item>
         <item name="colorControlNormal">#fff</item>
         <item name="colorControlHighlight">#3fff</item>
     </style>
    
    
    <style name="HeaderBar">
        <!-- Define the toolbar background -->
        <item name="android:background">xxxx</item>
    </style>