如何更改工具栏导航和溢出菜单图标(appcompat v7)?

49

我在使用v7工具栏时遇到了困难。 曾经对于ActionBar来说是很简单的任务,现在似乎过于复杂。 无论我设置什么样式,都无法更改导航图标(用于打开抽屉)或溢出菜单图标(用于打开菜单)。

因此,我有一个工具栏

<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="wrap_content"
    android:background="@color/ghex"
    android:minHeight="?attr/actionBarSize"
    app:theme="@style/ThemeOverlay.AppCompat.Light"
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
    >

我编写的代码如下

//before in the code I do
mToolbar = (Toolbar) findViewById(R.id.toolbar);

private void initToolbar() {
    setSupportActionBar(mToolbar);
    getSupportActionBar().setDisplayShowTitleEnabled(false);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setHomeButtonEnabled(true);
}

现在,我需要更改这两个图标的Drawable

如何为compat v7 Toolbar做到这一点?我想当抽屉打开时(Android 5.0),需要更改箭头的可见性。

12个回答

0

要更改选项菜单项的颜色,您可以

override fun onCreateOptionsMenu(menu: Menu?): Boolean {
    menuInflater.inflate(R.menu.your_menu, menu)

    menu?.forEach {
        it.icon.setTint(Color.your_color)
    }

    return true
}

-1
为了显示图标,请使用getSupportActionBar().setIcon(R.xxx.xxx) 在我的情况下,代码如下: getSupportActionBar().setIcon (R.mipmap.ic_launcher);

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