MaterialDrawer lib 项目中未显示导航抽屉图标
Navigation drawer icon not showing in MaterialDrawer lib project
我使用了 material 从 github https://github.com/mikepenz/MaterialDrawer
下载的抽屉库项目
遵循我的代码
final Toolbar toolbar = (Toolbar) findViewById(R.id.activity_main_toolbar);
toolbar.setTitleTextColor(Color.WHITE);
setSupportActionBar(toolbar);
result = new Drawer()
.withActivity(this)
.withToolbar(toolbar)
.withHeader(R.layout.header)
.withActionBarDrawerToggleAnimated(true)
.withActionBarDrawerToggle(true)
.addDrawerItems(
new PrimaryDrawerItem().withName(R.string.category_all).withIdentifier(Category.ALL.id).withIcon(GoogleMaterial.Icon.gmd_landscape),
new PrimaryDrawerItem().withName(R.string.category_featured).withIdentifier(Category.FEATURED.id).withIcon(GoogleMaterial.Icon.gmd_grade),
new SectionDrawerItem().withName(R.string.category_section_categories),
new PrimaryDrawerItem().withName(R.string.category_buildings).withIdentifier(Category.BUILDINGS.id).withIcon(GoogleMaterial.Icon.gmd_location_city),
new PrimaryDrawerItem().withName(R.string.category_food).withIdentifier(Category.FOOD.id).withIcon(GoogleMaterial.Icon.gmd_local_bar),
new PrimaryDrawerItem().withName(R.string.category_nature).withIdentifier(Category.NATURE.id).withIcon(GoogleMaterial.Icon.gmd_local_florist),
new PrimaryDrawerItem().withName(R.string.category_objects).withIdentifier(Category.OBJECTS.id).withIcon(GoogleMaterial.Icon.gmd_style),
new PrimaryDrawerItem().withName(R.string.category_people).withIdentifier(Category.PEOPLE.id).withIcon(GoogleMaterial.Icon.gmd_person),
new PrimaryDrawerItem().withName(R.string.category_technology).withIdentifier(Category.TECHNOLOGY.id).withIcon(GoogleMaterial.Icon.gmd_local_see),
new PrimaryDrawerItem().withName(R.string.category_love).withIdentifier(Category.LOVED.id).withIcon(GoogleMaterial.Icon.gmd_local_florist)
)
.withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l, IDrawerItem drawerItem) {
if (drawerItem != null) {
if (drawerItem instanceof Nameable) {
toolbar.setTitle(((Nameable) drawerItem).getNameRes());
}
if (onFilterChangedListener != null) {
onFilterChangedListener.onFilterChanged(drawerItem.getIdentifier());
}
}
}
})
.build();
//disable scrollbar :D it's ugly
result.getListView().setVerticalScrollBarEnabled(false);
我尝试了所有方法来在工具栏中显示导航抽屉图标,但没有成功。
请帮助我。
我从 github android 演示项目中找到了答案。
https://github.com/mikepenz/MaterialDrawer/blob/develop/app/src/main/java/com/mikepenz/materialdrawer/app/ActionBarDrawerActivity.java
将操作栏设置为工具栏后放置此行代码。
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(false);
我使用了 material 从 github https://github.com/mikepenz/MaterialDrawer
下载的抽屉库项目遵循我的代码
final Toolbar toolbar = (Toolbar) findViewById(R.id.activity_main_toolbar);
toolbar.setTitleTextColor(Color.WHITE);
setSupportActionBar(toolbar);
result = new Drawer()
.withActivity(this)
.withToolbar(toolbar)
.withHeader(R.layout.header)
.withActionBarDrawerToggleAnimated(true)
.withActionBarDrawerToggle(true)
.addDrawerItems(
new PrimaryDrawerItem().withName(R.string.category_all).withIdentifier(Category.ALL.id).withIcon(GoogleMaterial.Icon.gmd_landscape),
new PrimaryDrawerItem().withName(R.string.category_featured).withIdentifier(Category.FEATURED.id).withIcon(GoogleMaterial.Icon.gmd_grade),
new SectionDrawerItem().withName(R.string.category_section_categories),
new PrimaryDrawerItem().withName(R.string.category_buildings).withIdentifier(Category.BUILDINGS.id).withIcon(GoogleMaterial.Icon.gmd_location_city),
new PrimaryDrawerItem().withName(R.string.category_food).withIdentifier(Category.FOOD.id).withIcon(GoogleMaterial.Icon.gmd_local_bar),
new PrimaryDrawerItem().withName(R.string.category_nature).withIdentifier(Category.NATURE.id).withIcon(GoogleMaterial.Icon.gmd_local_florist),
new PrimaryDrawerItem().withName(R.string.category_objects).withIdentifier(Category.OBJECTS.id).withIcon(GoogleMaterial.Icon.gmd_style),
new PrimaryDrawerItem().withName(R.string.category_people).withIdentifier(Category.PEOPLE.id).withIcon(GoogleMaterial.Icon.gmd_person),
new PrimaryDrawerItem().withName(R.string.category_technology).withIdentifier(Category.TECHNOLOGY.id).withIcon(GoogleMaterial.Icon.gmd_local_see),
new PrimaryDrawerItem().withName(R.string.category_love).withIdentifier(Category.LOVED.id).withIcon(GoogleMaterial.Icon.gmd_local_florist)
)
.withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l, IDrawerItem drawerItem) {
if (drawerItem != null) {
if (drawerItem instanceof Nameable) {
toolbar.setTitle(((Nameable) drawerItem).getNameRes());
}
if (onFilterChangedListener != null) {
onFilterChangedListener.onFilterChanged(drawerItem.getIdentifier());
}
}
}
})
.build();
//disable scrollbar :D it's ugly
result.getListView().setVerticalScrollBarEnabled(false);
我尝试了所有方法来在工具栏中显示导航抽屉图标,但没有成功。 请帮助我。
我从 github android 演示项目中找到了答案。 https://github.com/mikepenz/MaterialDrawer/blob/develop/app/src/main/java/com/mikepenz/materialdrawer/app/ActionBarDrawerActivity.java
将操作栏设置为工具栏后放置此行代码。
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(false);