5

Gần đây tôi đã gặp sự cố với bố cục điều phối viên. Khi tôi cố gắng tạo bố cục thanh công cụ thu gọn đơn giản như trong ví dụ this, thanh công cụ sẽ ở dưới thanh trạng thái như trong ảnh chụp màn hình bên dưới (trên thiết bị preLolipop mọi thứ hoạt động tốt, vì ứng dụng không vẽ dưới thanh trạng thái).Thanh công cụ thu gọn - thanh công cụ trong thanh trạng thái

toolbar under statusbar (see back arrow)

đoạn mã của bố trí Hoạt động của tôi:

<?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" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true"> 

    <android.support.design.widget.AppBarLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:fitsSystemWindows="true" 
     android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> 

     <android.support.design.widget.CollapsingToolbarLayout 
      android:id="@+id/collapsingToolbar" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:fitsSystemWindows="true" 
      app:contentScrim="?attr/colorPrimary" 
      app:layout_scrollFlags="scroll|exitUntilCollapsed"> 

      <ImageView 
       android:id="@+id/imageCalculationDetail" 
       android:layout_width="match_parent" 
       android:layout_height="200dp" 
       android:background="@drawable/ic_dummy_calculation" 
       android:fitsSystemWindows="true" 
       android:scaleType="centerCrop" 
       app:layout_collapseMode="parallax"/> 

      <android.support.v7.widget.Toolbar 
       android:id="@+id/toolbar" 
       android:layout_width="match_parent" 
       android:layout_height="?attr/actionBarSize" 
       android:background="@color/transparent" 
       app:layout_collapseMode="pin" 
       app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/> 

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

    <android.support.v4.widget.NestedScrollView 
     android:id="@+id/scroll" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_gravity="fill_vertical" 
     android:clipToPadding="false" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior"> 

     <include layout="@layout/container"/> 

    </android.support.v4.widget.NestedScrollView> 

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

My Styles (chỉ v21), nơi BaseAppTheme mẹ là Theme.AppCompat.Light.NoActionBar:

<style name="AppTheme" parent="BaseAppTheme"> 
     <item name="android:windowTranslucentStatus">true</item> 
     <item name="android:windowDrawsSystemBarBackgrounds">true</item> 
     <item name="colorPrimary">@color/colorPrimary</item> 
     <item name="android:colorPrimaryDark">@color/colorPrimaryDark</item> 
     <item name="android:colorAccent">@color/colorPrimary</item> 
     <item name="android:colorButtonNormal">@color/button_state_list</item> 
     <item name="android:statusBarColor">@color/transparent</item> 
    </style> 
+0

Đăng tệp styles.xml của bạn. –

+0

Tôi đã thêm kiểu vào câu hỏi –

+0

Còn tệp kê khai của bạn thì sao? Bạn đã chỉ định đúng kiểu ở đó chưa? Đăng bài đó quá. Bởi vì tôi đã thử bố cục tương tự và mọi thứ đều tốt đẹp trên trình giả lập lollipop. –

Trả lời

-1

Áp dụng một breakpoint để bao gồm một marginTop vào thanh công cụ cho các thiết bị lollipop hoặc ở trên.

giá trị/dimens.xml

<dimen name="toolbar_margin_top">0dp</dimen> 

giá trị-v21/dimens.xml

<dimen name="toolbar_margin_top">24dp</dimen> 

một sau đó trong cách bố trí của bạn:

<android.support.v7.widget.Toolbar 
    ..... 
    android:layout_marginTop="@dimen/toolbar_margin_top" 
+0

Điều này có vẻ giống như cách giải quyết khác, tôi muốn có một số giải pháp sạch sẽ, không có lợi nhuận hàng đầu trong [ví dụ] (http://antonioleiva.com/ collapsing-toolbar-layout /) –

+0

Nếu bạn muốn có một thanh trạng thái trong suốt, đó là cách duy nhất để sửa chữa nó. Khác, bạn cần phải tắt thuộc tính android: windowDrawsSystemBarBackgrounds theo kiểu của bạn: false

0
<item name="android:windowDrawsSystemBarBackgrounds">true</item> 

Bằng cách đặt này trong phong cách của bạn bạn đang nói với Android rằng ứng dụng của bạn có trách nhiệm r vẽ những thứ đằng sau thanh hệ thống. Đó là lý do tại sao "hack bẩn" trong câu trả lời khác là kỹ thuật chính xác nếu cờ này được thiết lập.

Trừ khi bạn có lý do rõ ràng cho cờ là đúng (tôi nghi ngờ là không), hãy đặt thành sai để Hệ điều hành bù đắp đúng nội dung của bạn cho bạn. Thanh trạng thái của bạn vẫn phải mờ.

+0

Không đặt giá trị này thành false sẽ không tạo bất kỳ sự khác biệt nào –

0

Hãy thử bằng cách loại bỏ android:fitsSystemWindows="true" từ ImageView ..

<ImageView 
      android:id="@+id/imageCalculationDetail" 
      android:layout_width="match_parent" 
      android:layout_height="200dp" 
      android:background="@drawable/ic_dummy_calculation" 
      android:scaleType="centerCrop" 
      app:layout_collapseMode="parallax"/> 
+0

Sau khi xóa cờ này, thanh công cụ nằm trong thanh trạng thái , nhưng thanh trạng thái dừng trong suốt và toàn bộ thanh công cụ thu gọn bị hủy bỏ, đây không phải là hiệu ứng mong muốn –

+0

bạn có vui lòng đăng ảnh chụp màn hình không? –

5

Vâng, tôi hình dung nó ra, vấn đề là tôi có

<item name="android:fitsSystemWindows">true</item> 

trong toolbarStyle của tôi về BaseAppTheme (ví actvities khác, mọi thứ đều hoạt động tốt , để thu gọn thanh công cụ có thanh trạng thái mờ). Sau khi đặt

android:fitsSystemWindows="false" 

vào thanh công cụ của tôi, mọi thứ đều hoạt động tốt.

0

Đối với tôi

Thêm thuộc tính fitSystemWindows = "false" vào Thanh công cụ trong XML đã hoạt động.

<android.support.v7.widget.Toolbar 
       android:id="@+id/toolbar" 
       android:layout_width="match_parent" 
       android:layout_height="?attr/actionBarSize" 
       android:fitsSystemWindows="false" 
       app:popupTheme="@style/AppTheme.PopupOverlay" 
       app:layout_collapseMode="pin"/> 
Các vấn đề liên quan