Java 在工具栏中从左到右对齐
我有一个工具栏,我想将文本向左对齐,而不是向右对齐 Main.xml文件代码为:Java 在工具栏中从左到右对齐,java,android,toolbar,Java,Android,Toolbar,我有一个工具栏,我想将文本向左对齐,而不是向右对齐 Main.xml文件代码为: <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent"> <include android:id="@+id/main_page_toolbar" layout="@layout
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<include
android:id="@+id/main_page_toolbar"
layout="@layout/app_bar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
</include>
不要设置标题,只需在工具栏中添加TextView即可 这里是演示
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar_top"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:minHeight="?attr/actionBarSize"
android:background="@color/action_bar_bkgnd"
app:theme="@style/ToolBarTheme" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Toolbar Title"
android:layout_gravity="center"
android:id="@+id/toolbar_title" />
</android.support.v7.widget.Toolbar>
由于您的文本是希伯来文,因此默认情况下,工具栏支持RTL支持的所有语言的RTL。我猜你是在要求覆盖文本的RTL行为 为了使文本左对齐,请将此属性添加到
工具栏中
android:layoutDirection = "ltr"
在你的app_bar_layout.xml中包括Textview
如果您的整个应用程序都应该使用RTL,您应该转到
style.xml
并将其添加到AppTheme:
<item name="android:layoutDirection">rtl</item>
rtl
当然,不要忘记在您的
AndroidManifest.xml
文件中的应用程序标签下添加android:supportsRtl=“true”
。Hi,如果我在java文件中输入注释所有代码并按照您的建议添加Textview,我得到了一个空白的白色工具栏,没有任何标题……我的文本颜色是白色的,这就是文本不可见的原因。太多了!我的文本颜色是白色的,这就是文本不可见的原因。太多了!是的,你刚刚更改了文本视图的文本颜色我的文本颜色是白色的,这就是文本不可见的原因。太多了!
android:layoutDirection = "ltr"
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/main_app_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textColor="#000000"
android:text="@string/app_name"
android:gravity="right"
/>
</android.support.v7.widget.Toolbar>
<item name="android:layoutDirection">rtl</item>