Java 文本赢得';t从顶部开始,重力=顶部
我一直在尝试将工具栏的标题设置为从工具栏顶部开始,但是,尽管我设置了Java 文本赢得';t从顶部开始,重力=顶部,java,android,xml,textview,android-toolbar,Java,Android,Xml,Textview,Android Toolbar,我一直在尝试将工具栏的标题设置为从工具栏顶部开始,但是,尽管我设置了android:gravity=“top”,但文本仍然从工具栏的中心(垂直)开始。我认为这可能与使用工具栏的自定义布局有关,但我之所以使用它是因为我需要它,所以我希望有人知道如何将文本设置为从顶部开始 以下是我的工具栏的布局: <?xml version="1.0" encoding="utf-8"?> <!--suppress AndroidDomInspection --> <RelativeL
android:gravity=“top”
,但文本仍然从工具栏的中心(垂直)开始。我认为这可能与使用工具栏的自定义布局有关,但我之所以使用它是因为我需要它,所以我希望有人知道如何将文本设置为从顶部开始
以下是我的工具栏的布局:
<?xml version="1.0" encoding="utf-8"?>
<!--suppress AndroidDomInspection -->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<android.support.percent.PercentRelativeLayout
android:id="@+id/layoutProjectOverview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="1dp">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar2"
android:title="@string/menuLabel1a"
app:layout_widthPercent="37%"
app:layout_heightPercent="26%"
android:gravity="top"
app:titleTextAppearance="@style/toolbarTitleText"
android:background="@drawable/toolbar_basic"
android:theme="@style/AppTheme.AppBarOverlay"
app:popupTheme="@style/AppTheme.PopupOverlay" />
<android.support.percent.PercentRelativeLayout
android:id="@+id/layoutObjectNav"
app:layout_widthPercent="63%"
app:layout_aspectRatio="400%"
android:layout_toRightOf="@id/toolbar2"
android:layout_toEndOf="@id/toolbar2"
android:background="@drawable/border_basic">
<!-- Some irrelevant xml code -->
</android.support.percent.PercentRelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/layoutObjectNav">
<!-- Some more irrelevant xml code -->
</RelativeLayout>
</android.support.percent.PercentRelativeLayout>
<!-- Some more irrelevant xml code -->
</RelativeLayout>
有人知道我做错了什么吗
编辑:
以下是我用于工具栏的文本外观样式:
<style name="toolbarTitleText">
<item name="android:textSize">20sp</item>
<item name="android:maxLines">3</item>
</style>
20便士
3.
在工具栏中添加文本视图
像这样:
<android.support.v7.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</android.support.v7.widget.Toolbar>
在工具栏中添加文本视图 像这样:
<android.support.v7.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</android.support.v7.widget.Toolbar>
尝试执行以下操作: 1-使用
getSupportActionBar()禁用标题。setDisplayShowTitleEnabled(false)代码>
2-在工具栏下添加文本视图作为工具栏标题:
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar2"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/toolbar_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top"/>
</android.support.v7.widget.Toolbar>
尝试执行以下操作:
1-使用getSupportActionBar()禁用标题。setDisplayShowTitleEnabled(false)代码>
2-在工具栏下添加文本视图作为工具栏标题:
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar2"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/toolbar_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top"/>
</android.support.v7.widget.Toolbar>
根据工具栏的大小、textview的textsize和工具栏中的填充,textview是否还有重新定位的空间?我想是的,但我不确定您是否在这里的样式中忽略了重力:app:titleTextAppearance=“@style/toolbar TitleText”?@BHuelse不,我没有。另外,我刚刚在问题中添加了样式,包括工具栏的大小、textview的textsize和工具栏中的填充,是否还有空间让textview重新定位?我想是的,但我不确定您是否在样式中覆盖了重力:app:titleTextAppearance=“@style/toolbarTitleText”@BHuelse否,我没有。另外,我刚刚在问题中添加了样式这不是我要搜索的,我以前也试过,请看:请添加图片让我知道你想要什么这不是我要搜索的,我以前也试过,请看:请添加图片让我知道你想要什么我以前试过,但没有真正起作用,请看:我以前试过,但实际上不起作用,请看: