我在我的项目中使用支持库中的工具栏。而且我找不到如何更改文本对齐方式。默认情况下它位于左侧。但我需要把它移到中心。我认为有一个方法 setTitleTextAppearance() ,但我不明白它的用法。
最佳答案
添加您自己的 TextView
,它可以根据需要对齐:
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/green">
<!-- Below will add your text in the center of the toolbar -->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Your Text"
android:textColor="#ff0000"
android:textStyle="bold"/>
</android.support.v7.widget.Toolbar>
关于android - 工具栏上的标题文本对齐方式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27055555/