如何在java中的android中将工具栏标题设置为中心

如何在java中的android中将工具栏标题设置为中心,android,Android,我用java为工具栏设置了标题。它被设置在左边的角落,但我需要使这个中心 我如何才能使这个标题中心 如果您有任何帮助,我们将不胜感激。您必须将textview作为子级添加到工具栏中 toolbar = (Toolbar) findViewById(R.id.gen_toolbar_pln); setSupportActionBar(toolbar); toolbar.setTitle(R.string.title_General); 使用android提供的标准工具栏无法移动标题,您需要创建我

我用java为工具栏设置了标题。它被设置在左边的角落,但我需要使这个中心

我如何才能使这个标题中心


如果您有任何帮助,我们将不胜感激。

您必须将textview作为子级添加到工具栏中

toolbar = (Toolbar) findViewById(R.id.gen_toolbar_pln);
setSupportActionBar(toolbar);
toolbar.setTitle(R.string.title_General);

使用android提供的标准工具栏无法移动标题,您需要创建我们自己的工具栏,它可以像线性布局一样简单,具有重力顶部,子元素是一个文本视图,位于父元素的中心。是的,但不带中心,请更正它。谢谢@TimCastelijns
<android.support.v7.widget.Toolbar
            android:id="@+id/my_toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            app:layout_scrollFlags="scroll|enterAlways"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Dark">

            <TextView
                android:id="@+id/title_text"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:gravity="center_horizontal" />
        </android.support.v7.widget.Toolbar>