0

您好,我需要在ProfileSettingDrawerItem单击 a 时打开活动,但这是在 .not 中定义AccountHeaderBuilder()DrawerBuilder()。这是代码:

headerResult = new AccountHeaderBuilder()
    .withActivity(this)
    .withCompactStyle(true)
    .withHeaderBackground(R.drawable.header)
    .addProfiles(
        profile,
        profile2,
        //don't ask but google uses 14dp for the add account icon in gmail but 20dp for the normal icons (like manage account)
        item = new ProfileSettingDrawerItem().withName("Add Account").withDescription("Add Account").withIcon(new IconicsDrawable(this, GoogleMaterial.Icon.gmd_plus).actionBar().paddingDp(5).colorRes(R.color.material_drawer_dark_primary_text)).withIdentifier(PROFILE_SETTING),
        item1=   new ProfileSettingDrawerItem().withName("Manage Account").withIcon(GoogleMaterial.Icon.gmd_settings).withIdentifier(11)
    )
    .withSavedInstance(savedInstanceState)
    .build();

//Create the drawer
result = new DrawerBuilder()
    .withActivity(this)
    .withToolbar(toolbar)
    .withHasStableIds(true)
    .withDrawerLayout(R.layout.crossfade_drawer)
    .withDrawerWidthDp(72)
    .withGenerateMiniDrawer(true)
    .withAccountHeader(headerResult) //set the AccountHeader we created earlier for the header
    .addDrawerItems(
        new PrimaryDrawerItem().withName("NASLOVNA").withIcon(GoogleMaterial.Icon.gmd_sun).withIdentifier(1),
        new PrimaryDrawerItem().withName("MODA").withIcon(FontAwesome.Icon.faw_home).withBadge("22").withBadgeStyle(new BadgeStyle(Color.RED, Color.RED)).withIdentifier(2).withSelectable(false),
        new PrimaryDrawerItem().withName("LIFESTYLE").withIcon(FontAwesome.Icon.faw_gamepad).withIdentifier(3),
        new PrimaryDrawerItem().withName("LEPOTA I ZDRAVLJE").withIcon(GoogleMaterial.Icon.gmd_sun).withIdentifier(8),
        new PrimaryDrawerItem().withName("VODIC").withIcon(FontAwesome.Icon.faw_eye).withIdentifier(4),
        new PrimaryDrawerItem().withName("MAMA I DETE ").withIcon(GoogleMaterial.Icon.gmd_adb).withIdentifier(5),
        new PrimaryDrawerItem().withName("INTERVJU").withIcon(GoogleMaterial.Icon.gmd_sun).withIdentifier(6),
        new PrimaryDrawerItem().withName("BLOG").withIcon(GoogleMaterial.Icon.gmd_sun).withIdentifier(7),
        new SectionDrawerItem().withName(R.string.drawer_item_section_header),
        new SecondaryDrawerItem().withName("SETTINGS").withIcon(FontAwesome.Icon.faw_github),
        new SecondaryDrawerItem().withName("Contact").withIcon(GoogleMaterial.Icon.gmd_format_color_fill).withTag("Bullhorn")
    ) // add the items we want to use with our Drawer
    .withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {
        @Override
        public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {
            //    if (drawerItem instanceof Nameable) {
            Toast.makeText(CrossfadeDrawerLayoutActvitiy.this, ((Nameable) drawerItem).getName().getText(CrossfadeDrawerLayoutActvitiy.this), Toast.LENGTH_SHORT).show();
            if (drawerItem != null) {
                Intent intent = null;
                if (drawerItem.getIdentifier() == 1) {
                    intent = new Intent(CrossfadeDrawerLayoutActvitiy.this, AddAccount.class);
                } else if (drawerItem.getIdentifier() == 11) {
                    intent = new Intent(CrossfadeDrawerLayoutActvitiy.this, AddAccount.class);
                }
                if (intent != null) {
                   CrossfadeDrawerLayoutActvitiy.this.startActivity(intent);
                }
            }
            //we do not consume the event and want the Drawer to continue with the event chain
            return false;
        }
    })
    .withSavedInstance(savedInstanceState)
    .withShowDrawerOnFirstLaunch(true)
    .build();

item1 = new ProfileSettingDrawerItem().withName("Manage Account").withIcon(GoogleMaterial.Icon.gmd_settings).withIdentifier(11)按下打开 AddAccount.class后有什么办法吗?

4

1 回答 1

0

您可以OnAccountHeaderListener在其中定义 click 事件的监听器。

.withOnAccountHeaderListener(new AccountHeader.OnAccountHeaderListener() {
    @Override
    public boolean onProfileChanged(View view, IProfile profile, boolean current) {
        //catch the event here and launch your activity
        //false if you have not consumed the event and it should close the drawer
        return false;
    }
})
于 2017-05-27T03:26:35.460 回答