使用 URL 在底部导航栏项目图标内加载图像

Yas*_*ine 5 java android android-glide bottom-navigation-bar

我正在尝试使用底部导航栏的项目图标内的 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) {

        }
    });
Run Code Online (Sandbox Code Playgroud)

profilePicUrl确实有效,我已经将它用于另一个图像视图。但是,当我运行该应用程序时,图标的尺寸会根据我尝试加载的图片而变化,但内部没有图像,如下所示

Sam*_*wal 4

菜单不支持彩色图像

您不能在这些地方以及更多地方使用彩色图像:

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

基本上,任何视图都使用菜单文件作为其资源,不能有彩色图像。这就是为什么你看不到它。要亲自测试它,请在可绘制对象中拍摄一张彩色图像并将其设置为底部导航的图标。你注意到它以同样的方式出现。这证明了这一点

编辑


  1. 这篇文章提供了一些有关如何操作的信息
  2. 你可以这样做:
    mBottomNav.setItemIconTintList(null);
    
    Run Code Online (Sandbox Code Playgroud)