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

时间:2018-04-12 10:04:20

标签: android

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

我在java中设置了工具栏的标题。它设置在左角,但我需要建立这个中心。

如何制作此标题中心?

任何帮助都将不胜感激。

1 个答案:

答案 0 :(得分:0)

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

<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>