Java 如何在操作栏中正确设置图像和文本?
我试图在操作栏中设置用户的图像和名称,如下所示: 我没有使用工具栏。守则:Java 如何在操作栏中正确设置图像和文本?,java,android,android-actionbar,android-toolbar,Java,Android,Android Actionbar,Android Toolbar,我试图在操作栏中设置用户的图像和名称,如下所示: 我没有使用工具栏。守则: if (receiverImageURL == null || receiverImageURL.trim().isEmpty()) { final Bitmap circleLetterTile = tileProvider.getCircularLetterTile(receiverFullName); getSupportActionBar().setIcon(new BitmapDrawable
if (receiverImageURL == null || receiverImageURL.trim().isEmpty()) {
final Bitmap circleLetterTile = tileProvider.getCircularLetterTile(receiverFullName);
getSupportActionBar().setIcon(new BitmapDrawable(getResources(), circleLetterTile));
setTitle(" " +StringUtils.capitalizeFully(receiverFullName));
} else {
Glide.with(this).asBitmap().load(receiverImageURL).into(new CustomViewTarget<ImageView, Bitmap>(???????) {
@Override
protected void onResourceCleared(@Nullable Drawable placeholder) {
}
@Override
public void onLoadFailed(@Nullable Drawable errorDrawable) {
final Bitmap circleLetterTile = tileProvider.getCircularLetterTile(receiverFullName);
getSupportActionBar().setIcon(new BitmapDrawable(getResources(), circleLetterTile));
setTitle(" " +StringUtils.capitalizeFully(receiverFullName));
}
@Override
public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
final Bitmap circleAvatarBitmap = tileProvider.getCircularImage(resource);
getSupportActionBar().setIcon(new BitmapDrawable(getResources(), circleAvatarBitmap));
setTitle(" " +StringUtils.capitalizeFully(receiverFullName));
}
});
}
if(receiverImageURL==null | | receiverImageURL.trim().isEmpty()){
最终位图circleLetterTile=tileProvider.getCircularLetterTile(receiverFullName);
getSupportActionBar().setIcon(新的BitmapDrawable(getResources(),CircleLittle));
setTitle(“+StringUtils.capitalizely(接收方全名));
}否则{
Glide.with(this).asBitmap().load(receiverImageURL).into(新的CustomViewTarget(???){
@凌驾
受保护的void onResourceCleared(@Nullable-Drawable占位符){
}
@凌驾
public void onload失败(@Nullable Drawable errorDrawable){
最终位图circleLetterTile=tileProvider.getCircularLetterTile(receiverFullName);
getSupportActionBar().setIcon(新的BitmapDrawable(getResources(),CircleLittle));
setTitle(“+StringUtils.capitalizely(接收方全名));
}
@凌驾
public void onResourceReady(@NonNull Bitmap resource,@Nullable Transition,带有ActionBar
您可以使用:
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayUseLogoEnabled(true);
getSupportActionBar().setLogo(R.drawable.xxxx);
使用工具栏
:
Toolbar toolbar = findViewById(R.id.toolbar);
toolbar.setLogo(R.drawable.xxxxx);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
使用操作栏
,您可以使用:
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayUseLogoEnabled(true);
getSupportActionBar().setLogo(R.drawable.xxxx);
使用工具栏
:
Toolbar toolbar = findViewById(R.id.toolbar);
toolbar.setLogo(R.drawable.xxxxx);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);