在JAVA中如何在android的中心设置工具栏标题
我知道在中间设置工具栏标题的布局方式。(在工具栏中具有文本视图) 我正在寻找同样的java方式。 这是我的工具栏布局在JAVA中如何在android的中心设置工具栏标题,android,Android,我知道在中间设置工具栏标题的布局方式。(在工具栏中具有文本视图) 我正在寻找同样的java方式。 这是我的工具栏布局 <android.support.v7.widget.Toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@color/colorPrimary" and
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimary"
android:minHeight="?attr/actionBarSize">
</android.support.v7.widget.Toolbar>
默认情况下,标题是左对齐的
是否有任何方法(在不更改布局的情况下)使标题居中对齐?工具栏小部件可以具有子视图,可用于自定义工具栏的外观居中文本的方法是使用TextView作为工具栏的子级,然后自定义它
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimary"
android:minHeight="?attr/actionBarSize">
<TextView
android:id="@+id/text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="@string/app_name"
android:textColor="@color/black" />
</android.support.v7.widget.Toolbar>
工具栏小部件可以有子视图,用于自定义工具栏的外观居中文本的方法是使用TextView作为工具栏的子级,然后自定义它
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimary"
android:minHeight="?attr/actionBarSize">
<TextView
android:id="@+id/text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="@string/app_name"
android:textColor="@color/black" />
</android.support.v7.widget.Toolbar>
如果你能检查一下我明确提到的JAVA方式的问题。您提到的可能重复项在布局文件中提供了一种解决问题的方法problem@DanielNugent添加了有问题的工具栏布局。如果你能检查这个问题,我已经清楚地提到了JAVA方式。您提到的可能重复项在布局文件中提供了一种解决问题的方法problem@DanielNugent添加了有问题的工具栏布局。