Android工具栏文本视图匹配\u父项变得比屏幕大

Android工具栏文本视图匹配\u父项变得比屏幕大,android,layout,center,toolbar,Android,Layout,Center,Toolbar,我有一个工具栏,里面有一个文本视图,其中有match\u parent来居中显示文本,但每次我这样做时,它都会比屏幕大并隐藏文本 这里有一个正在运行的it捕获 这在预览中是什么样子的 最后,我如何实施它: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http:

我有一个工具栏,里面有一个文本视图,其中有
match\u parent
来居中显示文本,但每次我这样做时,它都会比屏幕大并隐藏文本

这里有一个正在运行的it捕获

这在预览中是什么样子的

最后,我如何实施它:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    android:orientation="vertical">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        tools:layout_editor_absoluteY="0dp"
        tools:layout_editor_absoluteX="8dp">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:theme="@style/ToolBarStyle" >

            <TextView
                android:id="@+id/toolbar_title"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:gravity="center"
                android:text="@string/title_activity_anuncios" />

        </android.support.v7.widget.Toolbar>

    </android.support.design.widget.AppBarLayout>

    <android.support.constraint.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

    </android.support.constraint.ConstraintLayout>

</LinearLayout>

将其放在工具栏中

app:contentInsetStart="0dp"

检查样式主题或从清单中设置活动主题

 android:theme="@android:style/Theme.Translucent.NoTitleBar" 
如果活动主题正确,则可以检查活动>>onCreate方法

   ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setTitle("Your Title");
    } 

谢谢,我完全忘了