更改Android上工具栏中DrawerToggle的颜色
问题描述:
任何人都可以指出为什么我的抽屉开关(用于打开导航抽屉的动画的小汉堡图标)拒绝切换我的颜色吗?这给我造成了很多停机时间,我似乎无法弄清楚原因。更改Android上工具栏中DrawerToggle的颜色
这是我的主题 - 抽屉切换采用disabled_default_text的颜色。
<style name="Theme.MyApp.NoActionBar" parent="Theme.MyApp.NoActionBar">
<item name="actionBarStyle">@style/Widget.MyApp.ActionBar</item>
<item name="colorAccent">@color/cs7</item>
<item name="colorControlNormal">@color/disabled_default_text</item>
</style>
而这里的工具栏布局:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@drawable/ab_solid"
android:minHeight="?attr/actionBarSize"
app:theme="@style/MyToolbarTheme"
app:elevation="@dimen/toolbar_elevation"/>
MyToolbarTheme - 在我覆盖colorControlNormal用白色。
<style name="MyToolbarTheme" parent="@style/Widget.AppCompat.ActionBar.Solid">
<item name="background">@drawable/ab_solid</item>
<item name="titleTextStyle">@style/MyTitleStyle</item>
<item name="colorControlNormal">@color/white</item>
</style>
有什么奇怪的是,加入colorControlNormal改变从disabled_default_text颜色为白色溢出菜单的颜色,但抽屉切换不会得到改变。任何人都可以弄清楚我做错了什么?
答
证明这一点:
style.xml
<style name="AppTheme" parent="AppTheme.Base"></style>
<style name="AppTheme.Base" parent="Theme.AppCompat.NoActionBar">
<item name="colorPrimary">@color/theme_primary</item>
<item name="colorPrimaryDark">@color/theme_dark</item>
<item name="colorAccent">@color/theme_accent</item>
<item name="android:windowBackground">@color/theme_wbackground</item>
</style>
风格v21.xml
<style name="AppTheme" parent="AppTheme.Base">
<item name="android:colorPrimary">@color/theme_primary</item>
<item name="android:colorPrimaryDark">@color/theme_dark</item>
<item name="android:colorAccent">@color/theme_accent</item>
<item name="android:windowBackground">@color/theme_wbackground</item>
<item name="android:navigationBarColor">@color/theme_primary</item>
</style>
和INT工具栏: app_bar.xml
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/theme_primary"/>
答
你可以加drawerArrowStyle
你的主题为
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="drawerArrowStyle">@style/MyDrawerArrowToggle</item>
</style>
,你可以定制你MyDrawerArrowToggle
作为
<style name="MyDrawerArrowToggle" parent="Widget.AppCompat.DrawerArrowToggle">
<item name="color">@color/white</item>
</style>
答
上述解决方案使用的风格,这可能会work.But如果你想与你的icon.Hope来代替它这个将有助于某人。
DrawerLayout mDrawerLayout = (DrawerLayout)findViewById(R.id.drawerLayout);
Toolbar mToolbar = (Toolbar)findViewById(R.id.toolbar);
ActionBarDrawerToggle mToggle = new ActionBarDrawerToggle(this, mDrawerLayout, mToolbar,
R.string.navigation_drawer_open, R.string.navigation_drawer_close);
mToggle.setDrawerIndicatorEnabled(false); // this is very important don't miss it
mToggle.setHomeAsUpIndicator(R.drawable.ic_action_logo); // here your logo
启用抽屉指示你失去监听切换,这就是为什么你必须自己来处理它的点击。
mToggle.setToolbarNavigationClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
mDrawerLayout.openDrawer(GravityCompat.START)
}
});
就是这样快乐编码:)
什么'Widget.MyApp.ActionBar'?如果您要创建[MCVE](http://stackoverflow.com/help/mcve),这将有所帮助。 – tachyonflux