簡體   English   中英

為什么后退按鈕沒有在工具欄中顯示中心?

[英]why back button not showing center in toolbar?

我正在使用折疊工具欄,我正在嘗試顯示后退按鈕,它沒有顯示在toolbar center_vertical中。

輸出 我得到的

有誰知道為什么我得到這個輸出?

風格

<style name="AppThemeNoActionBarNotch" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">#1A000000</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
    <item name="android:fitsSystemWindows">true</item>
</style>

我使用這種風格是因為我想在status bar也顯示圖像預覽。

布局文件

<?xml version="1.0" encoding="utf-8"?>
<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"
tools:context=".activity.PerformarEventActivity">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="@dimen/_200sdp"
android:fitsSystemWindows="true"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

<android.support.design.widget.CollapsingToolbarLayout
    android:id="@+id/collapsing_toolbar"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    app:contentScrim="@color/colorPrimary"
    app:expandedTitleMarginEnd="@dimen/_64sdp"
    app:expandedTitleMarginStart="@dimen/_48sdp"
    app:expandedTitleTextAppearance="@style/TextAppearance.AppCompat.Headline"
    app:layout_scrollFlags="scroll|exitUntilCollapsed">

    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">

        <ImageView
            android:id="@+id/imgperformarbg"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            android:scaleType="fitXY"
            android:background="@drawable/publiek"
            app:layout_collapseMode="parallax" />

        <View
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_gravity="bottom"
            android:background="@drawable/gradient"/>
    </RelativeLayout>

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        app:layout_collapseMode="pin"
        app:titleTextColor="@color/white" />

    </android.support.v7.widget.Toolbar>

</android.support.design.widget.CollapsingToolbarLayout>

</android.support.design.widget.AppBarLayout>

<include layout="@layout/content_main_sub" />  //RECYCLERVIEW LAYOUT


</android.support.design.widget.CoordinatorLayout>

這是我的代碼

    toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    toolbar.setTitle(performer_name);
    toolbar.setNavigationIcon(R.drawable.ic_arrow_back_black_24dp);

任何幫助將不勝感激

Toolbar 支持比 ActionBar 更集中的功能集。 從頭到尾,工具欄可能包含以下可選元素的組合: 導航按鈕。 這可能是向上箭頭、導航菜單切換、關閉、折疊、完成或應用程序選擇的其他字形。 此按鈕應始終用於訪問工具欄容器內的其他導航目的地及其指定內容,或者以其他方式離開工具欄指定的當前上下文。 導航按鈕在工具欄的最小高度內垂直對齊(如果設置)。

因此,如果您將 minHeight 屬性設置為與工具欄高度 (layout_height) 相同,則后退箭頭將垂直居中。

developer.android.com 中的更多說明

從樣式中刪除fitsSystemWindows="true"並將fitsSystemWindows="true"放入所有標簽后,它起作用了。

將 minHeight 屬性設置為與您的工具欄高度 (layout_height) 相同,后箭頭將垂直居中。

暫無
暫無

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

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