android 后退箭头按钮未位于工具栏的中央
Back arrow button not placed in center in toolbar in android
我在操作栏中显示了后退按钮(向上按钮),但它没有显示在栏的中央。
如图所示
我已经为工具栏设置了最小高度,我无法更改它。
我的xml代码如下:
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/offence_title"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:gravity="center"
android:background="?attr/colorPrimary"
android:minHeight="150dip"
android:paddingBottom="15dp"
android:paddingTop="15dp"
android:theme="?attr/actionBarTheme"
android:paddingRight="15dp">
<TextView
android:id="@+id/toolbar_title"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:maxLines="3"
android:textColor="#FFF"
android:textSize="25sp" />
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
<TextView
android:id="@+id/fine_bold"
style="?android:attr/textAppearanceLarge"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/app_bar"
android:padding="16dp"
android:textIsSelectable="true"
android:textSize="25sp"
android:textStyle="bold" />
<TextView
android:id="@+id/offence_details"
style="?android:attr/textAppearanceLarge"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/fine_bold"
android:padding="16dp"
android:textIsSelectable="true" />
</LinearLayout>
</ScrollView>
</RelativeLayout>
从您的 android.support.v7.widget.Toolbar
中删除顶部填充
喜欢:
<android.support.v7.widget.Toolbar
android:id="@+id/offence_title"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:gravity="center"
android:background="?attr/colorPrimary"
android:minHeight="150dip"
android:paddingBottom="15dp"
android:paddingTop="15dp" //remove this line from your xml
android:theme="?attr/actionBarTheme"
android:paddingRight="15dp">
您应该将 android:layout_width
设置为自定义高度,将 android:minHeight
设置为 ?attr/actionBarSize
。这确保固定元素沿顶部显示(在 minHeight
内居中),同时整个高度仍然扩展到您的较大高度。
<android.support.v7.widget.Toolbar
android:id="@+id/offence_title"
android:layout_width="match_parent"
android:layout_height="150dip"
android:layout_gravity="center"
android:gravity="center"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize"
android:paddingBottom="15dp"
android:paddingTop="15dp"
android:theme="?attr/actionBarTheme"
android:paddingRight="15dp">
我在操作栏中显示了后退按钮(向上按钮),但它没有显示在栏的中央。
如图所示
我已经为工具栏设置了最小高度,我无法更改它。
我的xml代码如下:
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/offence_title"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:gravity="center"
android:background="?attr/colorPrimary"
android:minHeight="150dip"
android:paddingBottom="15dp"
android:paddingTop="15dp"
android:theme="?attr/actionBarTheme"
android:paddingRight="15dp">
<TextView
android:id="@+id/toolbar_title"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:maxLines="3"
android:textColor="#FFF"
android:textSize="25sp" />
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
<TextView
android:id="@+id/fine_bold"
style="?android:attr/textAppearanceLarge"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/app_bar"
android:padding="16dp"
android:textIsSelectable="true"
android:textSize="25sp"
android:textStyle="bold" />
<TextView
android:id="@+id/offence_details"
style="?android:attr/textAppearanceLarge"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/fine_bold"
android:padding="16dp"
android:textIsSelectable="true" />
</LinearLayout>
</ScrollView>
</RelativeLayout>
从您的 android.support.v7.widget.Toolbar
喜欢:
<android.support.v7.widget.Toolbar
android:id="@+id/offence_title"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:gravity="center"
android:background="?attr/colorPrimary"
android:minHeight="150dip"
android:paddingBottom="15dp"
android:paddingTop="15dp" //remove this line from your xml
android:theme="?attr/actionBarTheme"
android:paddingRight="15dp">
您应该将 android:layout_width
设置为自定义高度,将 android:minHeight
设置为 ?attr/actionBarSize
。这确保固定元素沿顶部显示(在 minHeight
内居中),同时整个高度仍然扩展到您的较大高度。
<android.support.v7.widget.Toolbar
android:id="@+id/offence_title"
android:layout_width="match_parent"
android:layout_height="150dip"
android:layout_gravity="center"
android:gravity="center"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize"
android:paddingBottom="15dp"
android:paddingTop="15dp"
android:theme="?attr/actionBarTheme"
android:paddingRight="15dp">