动作栏中的Android Studio个人资料图像

问题描述 投票:0回答:1

如何将个人资料图像放在默认的ActionBar中?

一段时间以来,我的应用程序就像下面的图像:

Actions bar

在上面的图像中,第一个操作栏是默认的,第二个操作栏(带有图像和配置文件的名称)是我创建的。

我想将默认的ActionBar与内部图像一起使用,如下面的图像所示:

ActionBar with image

也许我需要自己创建一个自定义Actionbar,但是如果可以使用默认的ActionBar,我会尝试的。

android-studio android-actionbar
1个回答
0
投票

您可以使用自定义操作栏

actionbar.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/bg" />

    <TextView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:text="APP_Name" />
</LinearLayout>

Activity.java中添加以下行

Objects.requireNonNull(getSupportActionBar()).setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
getSupportActionBar().setCustomView(R.layout.actionbar);
© www.soinside.com 2019 - 2024. All rights reserved.