1

这个问题非常具体到https://github.com/mikepenz/MaterialDrawer定制。

我需要自定义我的帐户标题,如下所示:

  1. 任何时候都只有一个帐户
  2. 单击标题(整个区域)应该给我 DrawerClickListener#onItemClick 回调

我设法通过重定向配置文件列表侦听器来获取 DrawerClickListener#onItemClick 回调。但是标题选择在方向改变时丢失了。[我已经设置了保存的实例状态]。此外,onItemClick 提供 null IDrawerItem,因为它不是适配器的一部分。

我是否让它太复杂或 PrimaryDrawerItem 本身可以扩展为看起来像配置文件项目?

  1. 布局应该像带有额外字段的配置文件一样呈现
  2. 将加载 ImageHolder 更改为加载基于 url 的图像
4

2 回答 2

1

您的问题分为多个问题。那么让我从第一个问题开始。

  1. 任何时候都只有一个帐户

如果您是build您的AccountHeader,您可以只提供一份个人资料。构建标头后,您可以随时更新和修改此单个配置文件,只需调用:

//create the profile
final IProfile profile = new ProfileDrawerItem().withName("Mike Penz").withEmail("mikepenz@gmail.com").withIcon("https://avatars3.githubusercontent.com/u/1476232?v=3&s=460").withIdentifier(100);
//build your drawer or do your logic
...
//modify the profile
profile.withName("new name");
//notify the header about the changed profile
headerResult.updateProfile(profile);
  1. 单击标题(整个区域)应该给我 DrawerClickListener#onItemClick 回调

如果你点击某处,AccountHeader这将触发一个OnAccountHeaderSelectionViewClickListener

.withOnAccountHeaderSelectionViewClickListener(new AccountHeader.OnAccountHeaderSelectionViewClickListener() {
   @Override
   public boolean onClick(View view, IProfile profile) {
       return false;
   }
})
  1. 布局应该像带有额外字段的配置文件一样呈现

请添加更多详细信息,因为问题似乎不清楚。

  1. 将加载 ImageHolder 更改为加载基于 url 的图像

示例应用程序包含一个CustomDrawerItem通过 url 加载图标:CustomUrlPrimaryDrawerItem

于 2016-01-25T22:22:15.880 回答
0

Drawer Itemclick 监听器

您必须在 setupNavigation 中声明该方法。在导航页脚项目中,声明

List<IDrawerItem> stockyItems = new ArrayList<>();

然后为您的按钮编写 withOnDrawerItemClickListener

PrimaryDrawerItem primaryDrawerItem = new PrimaryDrawerItem()
            .withName("Settings")
            .withIcon(R.drawable.ic_settings)
            .withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {
                @Override
                public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {
                    Intent intent = new Intent(MainActivity.this, Settings.class);
                    startActivity(intent);
                    finish();
                    return true;
                }
            });

最后你必须通过对象

stockyItems.add(primaryDrawerItem);

完毕

于 2020-03-27T18:58:37.397 回答