簡體   English   中英

后退箭頭按鈕未置於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">

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM