我正在将工具栏
添加到我的应用程序中,但似乎出了问题。在应用程序中,我应该有一个位于屏幕右侧的按钮,以及中心的标题。但是当我在应用程序中深入时,我应该在左侧显示返回箭头,通过执行getSupportActionBar()。setDisplayHomeAsUpEnabled()
来实现。这个可以正常工作,但是当我添加返回按钮时,文本会向右移动,以便返回按钮可以有空间。请问有人能告诉我如何让我的按钮在右侧,并且标题始终处于中心位置,无论是否显示返回按钮?
这是我的工具栏xml布局代码:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
android:padding="5dp"
tools:ignore="MissingPrefix">
<RelativeLayout
android:id="@+id/toolbar_info_holder"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="@+id/toolbar_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:gravity="center"
android:textColor="@color/actionbar_title_color" />
<ImageView
android:id="@+id/toolbar_image"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true" />
<TextView
android:id="@+id/toolbar_count"
android:layout_width="13dp"
android:layout_height="13dp"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:background="@drawable/red_circle"
android:gravity="center"
android:text="4"
android:textColor="@color/white"
android:textSize="9sp" />
</RelativeLayout>
</android.support.v7.widget.Toolbar>