如何将 header 添加到 Mikepenz Material 抽屉
How can I add a header to Mikepenz Material Drawer
我正在使用 mikepenz material 抽屉库和主要和次要抽屉项目,但无法在 material 抽屉中添加 header。
我想添加一个 material 抽屉 header (带有名称和个人资料图片)而不是主要抽屉项目。
下面是我的代码
new DrawerBuilder().withActivity(this).build();
//primary items
PrimaryDrawerItem profile = new PrimaryDrawerItem()
.withIdentifier(1)
.withName("John Doe")
.withDescription("Edit Profile")
.withDescriptionTextColorRes(R.color.black_overlay)
.withIcon(R.drawable.avatar);
SecondaryDrawerItem home = (SecondaryDrawerItem) new SecondaryDrawerItem()
.withIdentifier(13)
.withName(R.string.drawer_item_home)
.withIcon(R.drawable.ic_home);
SecondaryDrawerItem play = (SecondaryDrawerItem) new SecondaryDrawerItem()
.withIdentifier(14)
.withName(R.string.drawer_item_play)
.withIcon(R.drawable.ic_play);
SecondaryDrawerItem custom = (SecondaryDrawerItem) new SecondaryDrawerItem()
.withIdentifier(15)
.withName(R.string.drawer_item_custom)
.withIcon(R.drawable.ic_custom);
SecondaryDrawerItem settings = (SecondaryDrawerItem) new SecondaryDrawerItem()
.withIdentifier(97)
.withName(R.string.drawer_item_settings)
.withIcon(R.drawable.ic_setting);
SecondaryDrawerItem about = (SecondaryDrawerItem) new SecondaryDrawerItem()
.withIdentifier(98)
.withName(R.string.help)
.withIcon(R.drawable.ic_help);
SecondaryDrawerItem logout = (SecondaryDrawerItem) new SecondaryDrawerItem()
.withIdentifier(99)
.withName(R.string.drawer_item_logout)
.withIcon(R.drawable.ic_logout);
new DrawerBuilder()
.withActivity(this)
.withToolbar(toolbar)
.withActionBarDrawerToggleAnimated(true)
.withTranslucentStatusBar(true)
.withFullscreen(true)
.withSavedInstance(savedInstanceState)
.addDrawerItems(
profile,
new SectionDrawerItem(),
home,
play,
custom,
new DividerDrawerItem(),
settings,
help,
logout
)
.withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {
@Override
public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {
return false;
}
})
.build();
我试着用这个代替主抽屉里的东西,但我收到了一个错误(请传递 activity)
AccountHeader headerResult = new AccountHeaderBuilder()
.addProfiles(
new ProfileDrawerItem().withName("John Doe").withEmail("Johndoe@email.com").withIcon(R.drawable.avatar)
).withOnAccountHeaderListener(new AccountHeader.OnAccountHeaderListener() {
@Override
public boolean onProfileChanged(View view, IProfile profile, boolean currentProfile) {
return false;
}
}).build();
谁能告诉我我错过了什么?请
- 删除此
new DrawerBuilder().withActivity(this).build();
- 现在您应该在设置抽屉之前创建帐户 header(对于
操作栏调用下方的示例)
- 在 DrawerBuilder 方法中你应该添加
.withAccountHeader(headerResult)
我正在使用 mikepenz material 抽屉库和主要和次要抽屉项目,但无法在 material 抽屉中添加 header。 我想添加一个 material 抽屉 header (带有名称和个人资料图片)而不是主要抽屉项目。
下面是我的代码
new DrawerBuilder().withActivity(this).build();
//primary items
PrimaryDrawerItem profile = new PrimaryDrawerItem()
.withIdentifier(1)
.withName("John Doe")
.withDescription("Edit Profile")
.withDescriptionTextColorRes(R.color.black_overlay)
.withIcon(R.drawable.avatar);
SecondaryDrawerItem home = (SecondaryDrawerItem) new SecondaryDrawerItem()
.withIdentifier(13)
.withName(R.string.drawer_item_home)
.withIcon(R.drawable.ic_home);
SecondaryDrawerItem play = (SecondaryDrawerItem) new SecondaryDrawerItem()
.withIdentifier(14)
.withName(R.string.drawer_item_play)
.withIcon(R.drawable.ic_play);
SecondaryDrawerItem custom = (SecondaryDrawerItem) new SecondaryDrawerItem()
.withIdentifier(15)
.withName(R.string.drawer_item_custom)
.withIcon(R.drawable.ic_custom);
SecondaryDrawerItem settings = (SecondaryDrawerItem) new SecondaryDrawerItem()
.withIdentifier(97)
.withName(R.string.drawer_item_settings)
.withIcon(R.drawable.ic_setting);
SecondaryDrawerItem about = (SecondaryDrawerItem) new SecondaryDrawerItem()
.withIdentifier(98)
.withName(R.string.help)
.withIcon(R.drawable.ic_help);
SecondaryDrawerItem logout = (SecondaryDrawerItem) new SecondaryDrawerItem()
.withIdentifier(99)
.withName(R.string.drawer_item_logout)
.withIcon(R.drawable.ic_logout);
new DrawerBuilder()
.withActivity(this)
.withToolbar(toolbar)
.withActionBarDrawerToggleAnimated(true)
.withTranslucentStatusBar(true)
.withFullscreen(true)
.withSavedInstance(savedInstanceState)
.addDrawerItems(
profile,
new SectionDrawerItem(),
home,
play,
custom,
new DividerDrawerItem(),
settings,
help,
logout
)
.withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {
@Override
public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {
return false;
}
})
.build();
我试着用这个代替主抽屉里的东西,但我收到了一个错误(请传递 activity)
AccountHeader headerResult = new AccountHeaderBuilder()
.addProfiles(
new ProfileDrawerItem().withName("John Doe").withEmail("Johndoe@email.com").withIcon(R.drawable.avatar)
).withOnAccountHeaderListener(new AccountHeader.OnAccountHeaderListener() {
@Override
public boolean onProfileChanged(View view, IProfile profile, boolean currentProfile) {
return false;
}
}).build();
谁能告诉我我错过了什么?请
- 删除此
new DrawerBuilder().withActivity(this).build();
- 现在您应该在设置抽屉之前创建帐户 header(对于 操作栏调用下方的示例)
- 在 DrawerBuilder 方法中你应该添加
.withAccountHeader(headerResult)