我知道這可能是一個愚蠢的問題,但是作為一個新手我無法解決這個問題。所以我想添加帶有后退導航按鈕的 actionBar,并且隱藏了 LinearLayout 的一部分。我該如何解決這個問題??代碼主活動.xml<?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" tools:context=".MainActivity"> <android.support.design.widget.AppBarLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:fitsSystemWindows="true" android:theme="@style/AppTheme.AppBarOverlay"> <android.support.v7.widget.Toolbar android:id="@+id/toolbar" android:elevation="4dp" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" android:background="?attr/colorPrimary" android:fitsSystemWindows="true" app:popupTheme="@style/AppTheme.PopupOverlay" app:navigationIcon="@drawable/ic_arrow_back_black_24dp"/> </android.support.design.widget.AppBarLayout> <include layout="@layout/content_main" /></android.support.design.widget.CoordinatorLayout>
2 回答

慕田峪9158850
TA貢獻1794條經驗 獲得超7個贊
您需要將布局行為添加到您的內容中
<include layout="@layout/content_main" app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

幕布斯6054654
TA貢獻1876條經驗 獲得超7個贊
你可以試試這個。由于您使用的是 CoordinatorLayout,因此您需要使用 layout_behaviour、layout_anchor 和 layout_anchorGravity 來正確對齊布局。只需在您的包含中添加以下行:
app:layout_behavior="@string/appbar_scrolling_view_behavior"
所以它會是這樣的:
<include layout="@layout/content_main"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
添加回答
舉報
0/150
提交
取消