Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/323.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/232.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何在操作栏中正确设置图像和文本?_Java_Android_Android Actionbar_Android Toolbar - Fatal编程技术网

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);