我想改变导航抽屉图标的颜色(3垂直条)从白色到灰色。我怎么用最简单的方法来做呢?
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
android:background="@color/grey"
local:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
local:popupTheme="@style/ThemeOverlay.AppCompat.Light" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Toolbar Title"
android:id="@+id/toolbar_title"
android:textColor="#010101" />
<!--android:layout_gravity="center"-->
</android.support.v7.widget.Toolbar>
您可以通过编程方式更改图标本身,使用如下代码:
toolbar.setNavigationIcon(R.drawable.new_icon);
把可拉的
Drawable icMenu = contextpat . getdrawable (this,R.drawable.ic_hamburguer);
着色可绘制
icMenu.setColorFilter (getresource () .getColor (android.R.color.darker_gray),PorterDuff.Mode.SRC_ATOP);
与actionBar一起使用
actionBar.setHomeAsUpIndicator (icMenu);
actionBar.setDisplayHomeAsUpEnabled(真正);
或者工具栏
toolbar.setNavigationIcon (icMenu);
更改工具栏主题
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
android:background="@color/grey"
local:theme="@style/CustomTheme"
local:popupTheme="@style/ThemeOverlay.AppCompat.Light" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Toolbar Title"
android:id="@+id/toolbar_title"
android:textColor="#010101" />
<!--android:layout_gravity="center"-->
</android.support.v7.widget.Toolbar>
在你的styles.xml
创建新样式
<style name="CustomTheme" parent="ThemeOverlay.AppCompat.Dark.ActionBar">
<item name="android:textColorPrimary">#COLOR_CODE_FOR_YOUR_TEXT</item>
<item name="android:textColorSecondary">#COLOR_CODE_FOR_YOUR_TOOLBAR_ICON</item>
</style>