简体   繁体   中英

how to change action bar toggle color? - android

How do i change the color of the action bar toggle?

在此处输入图片说明

Here is my code for my action bar in java:

  //Navigation view and Drawer layout
        drawerlayout = (DrawerLayout) findViewById(R.id.main_ND);
        actionBarDrawerToggle = new ActionBarDrawerToggle(this,drawerlayout,0,0);
        navigationView = (NavigationView) findViewById(R.id.main_NV);
        navigationView.setItemIconTintList(null);
        View headerView = navigationView.getHeaderView(0);
        nD_image = (ImageView) headerView.findViewById(R.id.nd_image);
        Glide.with(getBaseContext()).load(R.drawable.my_paper).centerCrop().into(nD_image);
        setNavigationView();
        drawerlayout.addDrawerListener(actionBarDrawerToggle);
        actionBarDrawerToggle.syncState();
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setHomeButtonEnabled(true);
}


 @Override
    public boolean onOptionsItemSelected(MenuItem item)
    {
        if(actionBarDrawerToggle.onOptionsItemSelected(item))
        {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

In my styles

  <style name="my_theme" parent="Theme.AppCompat.Light.NoActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimaryDark">@color/salmonDark</item>
        <item name="colorPrimary">@color/salmon_main</item>
        <item name="colorAccent">@color/black</item>
        <item name="android:actionMenuTextColor">@color/white</item><!-- green was: #8BC34A -->
        <item name="android:actionMenuTextAppearance">@style/actionBarTextSize</item>
    </style>

And then in my manifest

 <activity android:name=".Main.Main"
            android:screenOrientation="portrait"
            android:theme="@style/zivit_theme"/>

Im quite not sure how to change the color or where to do it. I hope someone can post some example code of the step by step process in (or that magic one line of code that does it) thank you!

try this:

in base theme: add an item for the action bar

 <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="android:actionBarStyle">@style/MyActionBar</item>
    <item name="drawerArrowStyle">@style/MyDrawerArrowToggle</item>

    <!-- Support library compatibility -->
    <item name="actionBarStyle">@style/MyActionBar</item>
</style>

custom action bar theme:

<style name="MyActionBar" parent="@style/Widget.AppCompat.ActionBar">
    <item name="android:titleTextStyle">@style/MyTitleTextStyle</item>
    <item name="android:background">@color/background</item>

     <!-- Support library compatibility -->
     <item name="titleTextStyle">@style/TitleTextStyle</item>
     <item name="background">@color/background</item>
</style>

you can also modify action bar text color:

<style name="MyTitleTextStyle" parent="@style/TextAppearance.AppCompat.Widget.ActionBar.Title">
    <item name="android:textColor">@color/foreground</item>
</style>

Toggle button style:

 <style name="MyDrawerArrowToggle" parent="Widget.AppCompat.DrawerArrowToggle">
    <item name="color">@color/foreground</item>
</style>

Up to API Level 11 , you cab define the color of action bar as follow

<resources> 
     <style name="MyTheme" parent="@android:style/Theme.Holo.Light"> 
        <item name="android:actionBarStyle">@style/MyActionBar</item> </style> 
    <style name="MyActionBar" parent="@android:style/Widget.Holo.Light.ActionBar">
   <item name="android:background">ANY_HEX_COLOR_CODE</item> </style> 
  </resources>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM