如何向Mikepenz材质抽屉添加页眉

时间:2020-04-20 23:12:17

标签: android materialdrawer

我正在将mikepenz材料抽屉库与主要和次要抽屉项目一起使用,但无法在材料抽屉中添加页眉。 我想添加一个物料抽屉标题(带有名称和配置文件图像)而不是主要抽屉项目。

下面是我的代码

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();

我尝试放置此物品而不是主要的抽屉物品,但出现错误(请传递活动)

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();

谁能告诉我我想念的东西吗?请。

1 个答案:

答案 0 :(得分:0)

  1. 删除此new DrawerBuilder().withActivity(this).build();
  2. 现在,您应该在设置抽屉(对于 操作栏调用下面的示例)
  3. 在DrawerBuilder方法中,您应该添加.withAccountHeader(headerResult)