如何更改操作栏切换颜色? - android

how to change action bar toggle color? - android

如何更改操作栏切换的颜色?

这是我在 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);
    }

我的风格

  <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>

然后在我的清单中

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

我不太确定如何更改颜色或在哪里更改。我希望有人可以 post 一些逐步过程的示例代码(或完成它的神奇的一行代码)谢谢!

直到 API 11 级,您可以将操作栏的颜色定义如下

<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>

试试这个:

在基本主题中:为操作栏添加一个项目

 <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>

自定义操作栏主题:

<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>

您还可以修改操作栏文字颜色:

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

切换按钮样式:

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