Android 如何在工具栏片段中居中放置字符串?
下面是XML的一部分,它在我的配置文件片段中生成了一个工具栏,背景为黑色,其中写入了配置文件。 虽然我试图将个人资料居中,但似乎没有任何效果。有什么建议吗Android 如何在工具栏片段中居中放置字符串?,android,kotlin,Android,Kotlin,下面是XML的一部分,它在我的配置文件片段中生成了一个工具栏,背景为黑色,其中写入了配置文件。 虽然我试图将个人资料居中,但似乎没有任何效果。有什么建议吗 <fragment android:id="@+id/navigation_home" android:name="com.example.myapp_android.ui.home.HomeFragment" android:label="@string/tit
<fragment
android:id="@+id/navigation_home"
android:name="com.example.myapp_android.ui.home.HomeFragment"
android:label="@string/title_home"
tools:layout="@layout/fragment_home" />
我尝试将工具栏添加到
中,以便您可以在工具栏中使用TextView
使用以下命令:
<androidx.appcompat.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/toolbar"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Toolbar"
android:textSize="20sp"
android:textStyle="bold"/>
</androidx.appcompat.widget.Toolbar>