如何改变工具栏导航和溢出菜单图标(应用程序兼容性V7)? [英] How to change Toolbar Navigation and Overflow Menu icons (appcompat v7)?
问题描述
我有一个困难时期,与V7工具栏。曾经是为动作条
一个简单的任务,现在看来过于复杂。无论我所设置的风格,我不能更改导航图标(这将打开一个抽屉)或溢出菜单图标(打开菜单)。
I am having a hard time with v7 Toolbar. What was once a simple task for ActionBar
, now seems overly complex. No matter what style I set, I cannot change either navigation icon (which opens a Drawer) or overflow menu icon (which opens a menu).
所以我有一个工具栏
<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"
>
我code,它看起来像这样
I code it looks like this
//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);
}
现在,我需要改变可绘制
为这两个图标。
Now, I need to change the Drawable
for those two icons.
我如何做到这一点的COMPAT V7 工具栏
?我想我需要改变箭头可见当抽屉被打开(的Android 5.0)。
How do I do this for compat v7 Toolbar
? I guess I would need to change the arrow visible when the drawer is open (Android 5.0).
推荐答案
要改变你可以使用导航图标:
To change the navigation icon you can use:
Toolbar toolbar = (Toolbar) findViewById(R.id.my_awesome_toolbar);
setSupportActionBar(toolbar);
toolbar.setNavigationIcon(R.drawable.my_icon);
要更改的菜单图标,你可以定义这样的风格:
To change the overflow icon you can define a style like this:
<style name="AppTheme.Base" parent="Theme.AppCompat.Light">
<item name="actionOverflowButtonStyle">@style/OverFlow</item>
</style>
<style name="OverFlow" parent="Widget.AppCompat.ActionButton.Overflow">
<item name="android:src">@drawable/my_overflow_menu</item>
</style>
在任何情况下,它可能是不是一个好主意来更改标准图标,像溢出菜单。
In any case, it could be not a good idea to change a standard icon, like the overflow menu.
如果你想改变,你可以使用图标的颜色:
If you would like to change the color of the icon you can use:
<android.support.v7.widget.Toolbar
app:theme="@style/ThemeToolbar" />
<style name="ThemeToolbar" parent="Theme.AppCompat.Light">
<!-- navigation icon color -->
<item name="colorControlNormal">@color/my_color</item>
<!-- color of the menu overflow icon -->
<item name="android:textColorSecondary">@color/my_color</item>
</style>
这篇关于如何改变工具栏导航和溢出菜单图标(应用程序兼容性V7)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!