2015-12-06 41 views
5

Tôi đang cố gắng triển khai Bố cục Thanh công cụ Thu gọn với các tùy chọn trình đơn nhưng bất cứ khi nào tôi đặt nguồn chế độ xem hình ảnh trong mã bên dưới, hình ảnh bao gồm menu và nút quay lại. Các tùy chọn có ở đó vì tôi có thể nhấp vào chúng, chúng chỉ bị ẩn bởi hình ảnh. Có ai biết làm thế nào để sửa lỗi này?Tùy chọn menu không hiển thị trên Thanh công cụ Thu gọn

XML Layout

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

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

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

      <ImageView 
       android:src="@drawable/background" 
       app:layout_scrollFlags="scroll|enterAlways|enterAlwaysCollapsed" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:scaleType="centerCrop" 
       app:layout_collapseMode="parallax" 
       android:minHeight="100dp" 
       android:fitsSystemWindows="true"/> 

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

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

Đây có phải là điều phối viên không? – Simon

+0

Có, tất cả hoạt động tốt ngoài các biểu tượng menu không hiển thị – Carl

Trả lời

5

hãy thử này:

<?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:id="@+id/coordinator" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true" > 

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

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

      <ImageView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       app:layout_collapseMode="parallax" 
       android:background="@drawable/background" 
       android:fitsSystemWindows="true" 
       android:minHeight="100dp" 
       android:scaleType="centerCrop" /> 

      <android.support.v7.widget.Toolbar 
       android:id="@+id/detail_toolbar" 
       android:layout_width="match_parent" 
       android:layout_height="?attr/actionBarSize" 
       app:layout_collapseMode="pin" 
       android:fitsSystemWindows="true" 
       app:popupTheme="@style/ThemeOverlay.AppCompat.Light" /> 
     </android.support.design.widget.CollapsingToolbarLayout> 
    </android.support.design.widget.AppBarLayout> 

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

nếu bất kỳ rắc rối nghỉ bình luận

chúc may mắn!

+0

, hãy thử thêm vào bên trong thanh công cụ của bạn: android: gravity = "center_vertical" – Netero

+6

Bạn có thể mô tả những gì bạn đã thay đổi giữa mã OP và mã trong câu trả lời của bạn không ? –

+1

@MichaelFulton: Mang Thanh công cụ đến cùng. Thanh công cụ sẽ là con cuối cùng của CollapsingToolbarLayout – thanhnd

3

Từ kinh nghiệm bản thân này nói với tôi điều này, bạn có thể đã quên để thêm dòng sau vào hoạt động:

thanh công cụ Toolbar = (Toolbar) findViewById (R.id.toolbar);

setSupportActionBar (thanh công cụ);

+0

cùng một điều xảy ra ở đây. Tôi đang sử dụng thanh công cụ trong phân đoạn và quên đặt mã này. Đề xuất là bất kỳ ai gặp vấn đề tương tự, hãy thử dòng này trước, khiến việc xác minh ngắn gọn và nhanh chóng. – Anthonyeef

1

Thử thêm thuộc tính collapseMode vào Thanh công cụ ... như thế này. Nó ghim thanh công cụ.

<android.support.v7.widget.Toolbar 


    app:layout_collapseMode="pin" /> 
Các vấn đề liên quan