如何在片段的工具栏中心设置标题

时间:2020-11-05 14:43:24

标签: android android-layout android-fragments

如何在片段的工具栏中央设置标题。

我尝试了各种方法,但是它们没有起作用。 我想将Tittle设置为大胆的风格。

enter image description here

enter image description here

我想将这些标题设置为大胆的风格

1 个答案:

答案 0 :(得分:2)

您可以像这样将text view放在toolbar内:

<androidx.appcompat.widget.Toolbar
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        app:layout_constraintTop_toTopOf="parent" >
        <TextView
            android:id="@+id/title"
            android:text="Title"
            android:textSize="20dp"
            android:layout_gravity="center"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/>
    </androidx.appcompat.widget.Toolbar>

,如果您想将text view文本设置为您的应用标题,请使用以下命令:

TextView t = (TextView) findViewById(R.id.title) ;
t.setText(getTitle()) ;

结果:

enter image description here

相关问题