Android 有菜单项时工具栏中心文本视图

Android 有菜单项时工具栏中心文本视图,android,toolbar,centering,Android,Toolbar,Centering,在阅读了SO中的多个问题/答案后,我仍在搜索答案。 我的问题:在我的应用程序中,我使用一个工具栏,但根据工具栏菜单项中的片段/活动可能会发生变化,例如,在第一个屏幕上,您将只看到一个文本视图,在另一个片段中,将有主箭头和溢出菜单,有时有两个菜单图标。问题是标题以可用空间为中心,即(工具栏空间-菜单项空间) 以下是我的工具栏xml: <android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk

在阅读了SO中的多个问题/答案后,我仍在搜索答案。
我的问题:在我的应用程序中,我使用一个工具栏,但根据工具栏菜单项中的片段/活动可能会发生变化,例如,在第一个屏幕上,您将只看到一个文本视图,在另一个片段中,将有主箭头和溢出菜单,有时有两个菜单图标。问题是标题以可用空间为中心,即(工具栏空间-菜单项空间)

以下是我的工具栏xml:

<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimaryDark"
app:contentInsetStart="0dp"
app:contentInsetLeft="0dp">

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:text="@string/ciwy"
        android:textSize="28sp"
        android:textColor="#fff"/>

</RelativeLayout>

正如您所看到的,我尝试了ContentInsertStart,但它没有改变任何东西。我还使用relativelayout将文本视图居中。我需要它至少在API 19上工作(在我的手机上试用)

是否有一个解决方案,即使在我的菜单项下,也可以在中间的文本中心? 编辑


找不到任何解决方案,我只是在RelativeLayout中添加了一个图像视图,就像home按钮一样。

我认为不会有简单的解决方案。
工具栏
根据菜单项的数量为其余视图分配空间。因此,当您将
文本视图
添加到
工具栏
并将其居中时,您将在剩余的可用空间中将其居中。
工具栏
考虑菜单项的原因是为了防止重叠;因此,如果您想使视图完全居中并避免重叠,则很可能必须将
工具栏
作为子类。同时尝试添加
app:contentInsetStartWithNavigation=“0dp”
到您的
工具栏
应用程序:contentInsetStartWithNavigation不起作用。小部件中的:
android:gravity=center如何?@SatanPandeya不起作用,仍然居中取决于剩余的空间