如何将个人资料图像放在默认的ActionBar中?
一段时间以来,我的应用程序就像下面的图像:
在上面的图像中,第一个操作栏是默认的,第二个操作栏(带有图像和配置文件的名称)是我创建的。
我想将默认的ActionBar与内部图像一起使用,如下面的图像所示:
也许我需要自己创建一个自定义Actionbar,但是如果可以使用默认的ActionBar,我会尝试的。
您可以使用自定义操作栏
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);