您好我正在使用" android.support.v4.widget.DrawerLayout"用于抽屉。我想改变抽屉图标的颜色。请告诉我如何做到这一点。我分享我的代码。请看看并建议我如何更改图标颜色更改。
toolbar = (Toolbar) findViewById(R.id.tool_bar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
toolbar.setNavigationIcon(R.drawable.drawer);
toolbar.hideOverflowMenu();
getSupportActionBar().setTitle(null);
ImageView img = (ImageView) findViewById(R.id.imgCourses);
mRecyclerView = (RecyclerView) findViewById(R.id.RecyclerView);
mRecyclerView.setHasFixedSize(true);
Drawer = (DrawerLayout) findViewById(R.id.DrawerLayout);
mAdapter = new MyAdapter(TITLES,NAME,EMAIL,PROFILE,this);
mRecyclerView.setAdapter(mAdapter);
mRecyclerView.setVerticalScrollBarEnabled(false);
mLayoutManager = new LinearLayoutManager(this);
mRecyclerView.setLayoutManager(mLayoutManager);
mDrawerToggle = new ActionBarDrawerToggle(this,
Drawer,
toolbar,
R.string.openDrawer,
R.string.closeDrawer)
{
@Override
public void onDrawerOpened(View drawerView) {
super.onDrawerOpened(drawerView);
}
@Override
public void onDrawerClosed(View drawerView) {
super.onDrawerClosed(drawerView);
}
};
Drawer.setDrawerListener(mDrawerToggle);
mDrawerToggle.syncState();
Drawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
答案 0 :(得分:6)
如果要更改颜色而不是图像图标,可以使用setColorFilter,如下所示:
toolbar.getNavigationIcon().setColorFilter(Color.RED, PorterDuff.Mode.MULTIPLY);
希望能帮到你。
答案 1 :(得分:3)
通过自定义drawer_toggle
来更改抽屉图标的颜色mDrawerToggle.getDrawerArrowDrawable().setColor(getResources().getColor(R.color.grey));
快乐编码:)
答案 2 :(得分:-1)
为什么不为ToolBar
使用自定义图标而不是更改颜色?将您所需的图标添加到drawable
文件夹,然后将其用作
toolbar.setNavigationIcon(R.drawable.ic_your_icon_name);