android - 工具栏上的标题文本对齐方式

标签 android toolbar

我在我的项目中使用支持库中的工具栏。而且我找不到如何更改文本对齐方式。默认情况下它位于左侧。但我需要把它移到中心。我认为有一个方法 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/

相关文章:

android - MediaPlayer onPrepared 未触发

android - AudioRecord:缓冲区溢出?

java - Android 以编程方式向工具栏添加按钮

xaml - Xamarin.Forms 工具栏项目图标大小

wpf - 解决方法在WPF中震荡工具栏中的菜单样式

android - Google Play 游戏 - 登录无限期循环

java - 游戏 - 使用带有 openCV 人脸检测的前置摄像头

Android:连续扫描所有AP(接入点)

android - 如果折叠,则在 backPressed 时工具栏消失

Android 工具栏项目未显示?