使用URL将图像加载到底部导航栏项目图标中

发布于 2025-01-26 05:45:25 字数 763 浏览 4 评论 0原文

我正在尝试使用firebase存储URL加载配置文件图像,其中包括我的代码:

 Glide.with(getApplicationContext()).asBitmap().load(profilePicUrl)
    .into(new CustomTarget<Bitmap>() {

        @Override
        public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
            Drawable profileImage = new BitmapDrawable(getResources(), resource);
            bottomNav.getMenu().getItem(4).setIcon(profileImage);
        }

        @Override
        public void onLoadCleared(@Nullable Drawable placeholder) {

        }
    });

profilepicurl确实有效,我已经将其用于其他图像视图。但是,当我运行应用程序时,图标的尺寸会更改与我要加载的图片相对应,但是里面没有图像,这是它的外观

I'm trying to load a profile image using the firebase storage url inside an item's icon of a bottom navigation bar, here's my code:

 Glide.with(getApplicationContext()).asBitmap().load(profilePicUrl)
    .into(new CustomTarget<Bitmap>() {

        @Override
        public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
            Drawable profileImage = new BitmapDrawable(getResources(), resource);
            bottomNav.getMenu().getItem(4).setIcon(profileImage);
        }

        @Override
        public void onLoadCleared(@Nullable Drawable placeholder) {

        }
    });

The profilePicUrl does work, I already use it to for another image view. However when I run the app, the dimensions of the icon changes corresponding to the picture that I'm trying to load but there's no image inside, here's how it looks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

高跟鞋的旋律 2025-02-02 05:45:25

菜单不支持彩色图像

图像,也无法使用更多:

  1. 底部导航中
  2. 导航抽屉中的
  3. 在弹出菜单中

您不能在这些地方使用彩色 对于其资源,无法具有彩色图像。这就是为什么您看不到它。要自己测试,请在可绘制的可绘制中拍摄彩色图像,并将其设置为底部导航的图标。您会注意到它以相同的方式出现。这证明了它

编辑


  1. this 帖子提供了一些有关如何做的信息,
  2. 您可以这样做:
      mbottomnav.setitemicontintlist(null);
     

Menus do not support coloured images

You can not use a coloured image in these places and a bit more also:

  1. In bottom navigation
  2. In navigation drawer
  3. In popup menu
  4. etc...

Basically which ever view uses a menu file for its resource, cannot have a coloured image. That is why you don't see it. To test it yourself, take a colourful image in your drawable and set it as an icon for the bottom navigation. You notice that it comes the same way. This proves it

Edits


  1. This post gives some info on how to do it
  2. You can do it this way:
    mBottomNav.setItemIconTintList(null);
    
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文