Попытка центрировать TextView на панели инструментов Android, но когда в задний стек добавлено представление, центрирование теряется. Кажется, что задний элемент не является частью панели инструментов, и это вызывает проблему.
Вот 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:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:layout_scrollFlags="scroll|enterAlways">
<FrameLayout
android:background="@color/primary"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- This is a centered title -->
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:layout_gravity="center"
android:layout_marginLeft="?attr/actionBarSize"
android:layout_marginRight="?attr/actionBarSize"
android:gravity="center_vertical|center_horizontal">
<TextView
android:id="@+id/toolbar_title"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Blah"
android:textSize="18dp"
android:textColor="@color/white"
style="@style/TextAppearance.AppCompat.Widget.ActionBar.Title.Inverse" />
</LinearLayout>
</FrameLayout>
When no back stack is centered:
Когда действие, добавленное в задний стек, показывает кнопку «Назад», а центрирование текста теряется: