[英]How to properly set an image and a text in the action bar?
我正在尝试在操作栏中设置用户的图像和名称,如下所示:
我没有使用工具栏。 编码:
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
语句),则该方法有效。 但我有以下问题:
?????
地方,但我不知道如何得到。setTitle(" " +StringUtils.capitalizeFully(receiverFullName));
中使用的空间。 对于 mocking 的边距(取自其他类似主题)。解决这两个问题的最简单方法是什么?
使用ActionBar
,您可以使用:
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayUseLogoEnabled(true);
getSupportActionBar().setLogo(R.drawable.xxxx);
使用Toolbar
:
Toolbar toolbar = findViewById(R.id.toolbar);
toolbar.setLogo(R.drawable.xxxxx);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.