如何在mikepenz导航抽屉中使用Glide更改用户配置文件图标?

时间:2018-05-02 09:45:13

标签: android navigation-drawer android-glide

我已经检查了文档: https://github.com/mikepenz/MaterialDrawer  我明白mikepenz导航抽屉没有图像加载器所以我应该使用它:   //初始化并创建图像加载器逻辑

DrawerImageLoader.init(new AbstractDrawerImageLoader() {
    @Override
    public void set(ImageView imageView, Uri uri, Drawable placeholder, String tag) {
        Glide.with(imageView.getContext()).load(uri).placeholder(placeholder).into(imageView);
    }

    @Override
    public void cancel(ImageView imageView) {
        Glide.clear(imageView);
    }

但我似乎不知道如何调用它或使用它,我希望能够在这里使用它:

  AccountHeader headerResult = new AccountHeaderBuilder()
                .withActivity(activity)
                .withHeaderBackground(R.drawable.clouds_background)
                .addProfiles(
                        new ProfileDrawerItem().withName(name).withEmail(email)
                        .withIcon()
                        .withTextColor(R.color.colorPrimaryDark)
                )

应该在withIcon()

中使用

2 个答案:

答案 0 :(得分:1)

请参阅以下内容添加网址图片:

 new ProfileDrawerItem().withName("Mike Penz").withEmail("mikepenz@gmail.com").withIcon("https://avatars3.githubusercontent.com/u/1476232?v=3&s=460").withIdentifier(100);

查看此文档link1link2

答案 1 :(得分:0)

使用占位符并像这样调用: Glide.with(imageView.getContext())负载(URI).placeholder(占位符).into(ImageView的);

将其插入“DrawerImageLoader初始化”:

  @Override
            public Drawable placeholder(Context ctx, String tag) {
                //define different placeholders for different imageView targets
                //default tags are accessible via the DrawerImageLoader.Tags
                //custom ones can be checked via string. see the CustomUrlBasePrimaryDrawerItem LINE 111
                if (DrawerImageLoader.Tags.PROFILE.name().equals(tag)) {
                    return DrawerUIUtils.getPlaceHolder(ctx);
                } else if (DrawerImageLoader.Tags.ACCOUNT_HEADER.name().equals(tag)) {
                    return new IconicsDrawable(ctx).iconText(" ").backgroundColorRes(com.mikepenz.materialdrawer.R.color.primary).sizeDp(56);
                } else if ("customUrlItem".equals(tag)) {
                    return new IconicsDrawable(ctx).iconText(" ").backgroundColorRes(R.color.md_red_500).sizeDp(56);
                }


                return super.placeholder(ctx, tag);
            }
        });