更改Android工具栏中抽屉切换的颜色
有人能指出为什么我的抽屉开关(一个小汉堡包图标,可以通过动画打开导航抽屉)拒绝在我身上切换颜色吗?这给我造成了很多停机时间,我似乎不知道为什么 这是我的主题-抽屉切换采用禁用的默认文本的颜色更改Android工具栏中抽屉切换的颜色,android,material-design,android-theme,android-styles,Android,Material Design,Android Theme,Android Styles,有人能指出为什么我的抽屉开关(一个小汉堡包图标,可以通过动画打开导航抽屉)拒绝在我身上切换颜色吗?这给我造成了很多停机时间,我似乎不知道为什么 这是我的主题-抽屉切换采用禁用的默认文本的颜色 <style name="Theme.MyApp.NoActionBar" parent="Theme.MyApp.NoActionBar"> <item name="actionBarStyle">@style/Widget.MyApp.ActionBar</item
<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>
@style/Widget.MyApp.ActionBar
@颜色/cs7
@颜色/禁用\u默认\u文本
下面是工具栏布局:
<?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>
@可拉伸/ab_实心
@样式/我的标题样式
@颜色/白色
奇怪的是,添加colorControlNormal会将溢出菜单的颜色从禁用的默认文本颜色更改为白色,但抽屉切换不会更改。有人能找出我做错了什么吗?证明这一点:
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>
@颜色/主题
@颜色/主题为深色
@颜色/主题/口音
@颜色/主题背景
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"/>
您可以将
抽屉行样式添加到主题中,如下所示
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="drawerArrowStyle">@style/MyDrawerArrowToggle</item>
</style>
上面的解决方案使用的样式可能会起作用。但如果你想用你的图标替换它,该怎么办呢。希望这对其他人有所帮助
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
?如果你能创建一个。
mToggle.setToolbarNavigationClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
mDrawerLayout.openDrawer(GravityCompat.START)
}
});