导航抽屉图标改变颜色

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>

1
只是一条注释,三个横向条形图标被称为汉堡包图标。 - Shashwat Black
在这里找到答案:https://dev59.com/Pl0Z5IYBdhLWcg3wfgYR - Alvaro de Lucas
3个回答

3

获取drawable

Drawable icMenu = ContextCompat.getDrawable(this, R.drawable.ic_hamburguer);

对drawable进行着色

icMenu.setColorFilter(getResources().getColor(android.R.color.darker_gray), PorterDuff.Mode.SRC_ATOP);

在actionBar中使用

actionBar.setHomeAsUpIndicator(icMenu);

actionBar.setDisplayHomeAsUpEnabled(true);

或在工具栏中使用

toolbar.setNavigationIcon(icMenu);


3
您可以通过编程方式更改图标本身,例如使用以下代码:
toolbar.setNavigationIcon(R.drawable.new_icon);

1
改变工具栏主题。
<?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>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接