Как я могу добавить заголовок в ящик материалов Mikepenz

Я использовал библиотеку ящиков материалов 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("[email protected]").withIcon(R.drawable.avatar)
    ).withOnAccountHeaderListener(new AccountHeader.OnAccountHeaderListener() {
        @Override
        public boolean onProfileChanged(View view, IProfile profile, boolean currentProfile) {
            return false;
        }
    }).build();

Может ли кто-нибудь сказать мне, что мне не хватает? пожалуйста.


person DroidUX    schedule 20.04.2020    source источник


Ответы (1)


  1. удали это new DrawerBuilder().withActivity(this).build();
  2. Теперь вы должны создать заголовок учетной записи перед установкой ящика (например, под вызовом панели действий)
  3. в методе DrawerBuilder вы должны добавить .withAccountHeader(headerResult)
person Wael Jomni    schedule 21.04.2020