[英]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.