我正在尝试从url加载BottomNavigationView的菜单项图标。我使用Picasso Library来加载图片。
navigationView = (BottomNavigationView)findViewById(R.id.bottom_navigation);
disableShiftMode(navigationView);
Menu menu = navigationView.getMenu();
int i=0;
for(BottomNavigationItem bottomNavigationItem : bottomNavigationItemList){
i(i<5){
final MenuItem navigationMenuItem = menu.getItem(i);
navigationMenuItem.setTitle(bottomNavigationItem.Name);
String icon_url = bottomNavigationItem.IconUrl;
final Target mTarget = new Target() {
@Override
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom loadedFrom) {
Log.d("DEBUG", "onBitmapLoaded");
BitmapDrawable mBitmapDrawable = new BitmapDrawable(getResources(), bitmap);
navigationMenuItem.setIcon(mBitmapDrawable);
}
@Override
public void onBitmapFailed(Drawable drawable) {
Log.d("DEBUG", "onBitmapFailed");
}
@Override
public void onPrepareLoad(Drawable drawable) {
Log.d("DEBUG", "onPrepareLoad");
}
};
Picasso.with(this).load(icon_url).into(mTarget);
}
i +=1;
}
如何确保加载所有图标?
答案 0 :(得分:0)
您可以在picasso调用中使用 .placeholder(),以便在加载网址图片时显示自定义图片。
这样的事情:
Picasso.with(this)
.load(icon_url)
.placeholder(R.drawable.image_name)
.into(mTarget);