簡體   English   中英

Android - Fragment中CoordinatorLayout狀態欄下的工具欄

[英]Android - Toolbar under status bar in CoordinatorLayout in Fragment

我正在使用CollapsingToolbarLayout開發一個屏幕。

當我在Activity中使用此布局時。 一切正常。

但是當我在Fragment中使用它時。 工具欄位於狀態欄下。

在活動中

在片段中

這是我的代碼。 請幫我。 謝謝。

<?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"
    >
  <!--App Bar Layout-->
  <android.support.design.widget.AppBarLayout
      android:id="@+id/appbar_layout"
      android:layout_width="match_parent"
      android:layout_height="300dp"
      android:fitsSystemWindows="true"
      >
    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/collapsed_toolbar"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_scrollFlags="scroll|exitUntilCollapsed|snap"
    app:contentScrim="?attr/colorPrimary"
    >
  <android.support.v4.view.ViewPager
      android:id="@+id/view_pager"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:fitsSystemWindows="true"
      app:layout_collapseMode="parallax"/>
  <ImageView
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:fitsSystemWindows="true"
      app:layout_collapseMode="parallax"
      android:src="@mipmap/ic_launcher"
      />
  <android.support.v7.widget.Toolbar
      android:id="@+id/toolbar"
      android:layout_width="match_parent"
      android:layout_height="?attr/actionBarSize"
      app:layout_collapseMode="pin"
      app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
      >
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/lay_topbar"
        >
      <ImageView
          android:id="@+id/img_logo"
          android:layout_width="44dp"
          android:layout_height="44dp"
          android:background="#FF0000"
          android:layout_centerVertical="true"
          />
      <ImageButton
          android:id="@+id/imb_home"
          android:layout_width="44dp"
          android:layout_height="44dp"
          android:background="#00FF00"
          android:layout_alignParentRight="true"
          android:layout_centerVertical="true"
          />
      <ImageButton
          android:id="@+id/imb_cart"
          android:layout_width="44dp"
          android:layout_height="44dp"
          android:background="#0000FF"
          android:layout_toLeftOf="@id/imb_home"
          android:layout_centerVertical="true"
          />
    </RelativeLayout>
  </android.support.v7.widget.Toolbar>

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

我遇到過同樣的問題。 將android:fitsSystemWindows =“true”放在Activity的布局(包含片段的Activity)的根目錄中,而不是在片段布局的根目錄中(在你的情況下是CoordinatorLayout)。

嘗試在CollapsingToolbarLayout中添加以下語句。

機器人:fitsSystemWindows = “真”

暫無
暫無

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

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