2016-06-12 35 views
5

Tôi đang cố gắng để disable the shadow below a transparent AppBarLayout/Toolbar. Dưới đây là cách bố trí:AppBarLayout cao ẩn thanh công cụ

<android.support.design.widget.CoordinatorLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:background="#000"> 

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

     <android.support.v7.widget.Toolbar 
      android:id="@+id/imagePreviewToolbar" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" /> 

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

    <include layout="@layout/content_image_preview" /> 
</android.support.design.widget.CoordinatorLayout> 

Tôi đã thử với

app:elevation="0dp" 

getSupportActionBar().setElevation(0); 

nhưng mà làm the UP arrow invisible. Tôi cũng đã cố gắng loại bỏ AppBarLayout và chỉ sử dụng Thanh công cụ, nhưng vấn đề vẫn tồn tại.

Bất kỳ ai có giải pháp?


EDIT:

Thay combo AppBarLayout + Thanh công cụ với mã này:

<android.support.v7.widget.Toolbar 
    android:id="@+id/imagePreviewToolbar" 
    android:layout_width="match_parent" 
    android:layout_height="?attr/actionBarSize" 
    android:background="@android:color/transparent" 
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" 
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light" 
    app:elevation="0dp"/> 

phần cố định vấn đề. Bây giờ Thanh công cụ trở nên vô hình chỉ khi thiết bị ở chế độ ngang! Trình chỉnh sửa bố cục Android Studio hiển thị cho tôi Thanh công cụ theo cả hai hướng tốt, vì vậy tôi không thực sự biết vấn đề có thể là gì ..

+0

Xin chào, bạn đã thử ứng dụng: elevation = "0dp" trên thanh công cụ.? thử nó với xml thay vì lập trình. @xmattjus thử liên kết này http://stackoverflow.com/a/31492804/2736849 –

+0

@MFaisalHyder Cảm ơn liên kết đã khắc phục được sự cố .. Bây giờ Thanh công cụ trở nên vô hình chỉ ở chế độ ngang. Và điều này vui vẻ có hoặc không có thuộc tính độ cao được thiết lập. – xmattjus

+0

không thay thế bố cục, sử dụng ToolBar bên trong AppBarLayout lần này thử ứng dụng: ele ... property để appbar Layout thay vì Toolbar cho tôi biết.một điều nữa thử trên các thiết bị/giả lập khác nhau –

Trả lời

11

sau một số lần thử, tôi đã thấy rằng ToolBar sẽ là chế độ xem cuối cùng trong trường hợp này nếu nó sẽ là đầu tiên sau đó xem đến sau khi nó sẽ chồng lên nhau vì nó có chiều cao thiết lập để match_parent vì vậy hãy thử cách này trong bố trí.

Layout

<?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" > 

<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_below="@+id/imagePreviewToolbar" > 

    <ImageView 
     android:id="@+id/image_preview" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:background="@drawable/galacticos" 
     android:contentDescription="abc" 
     android:scaleType="fitCenter" /> 

    <LinearLayout 
     android:id="@+id/actionBtns" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:orientation="horizontal" 
     android:padding="16dp" > 

     <ImageButton 
      android:id="@+id/setBackgroundBtn" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:background="@null" 
      android:contentDescription="abc" 
      android:src="@drawable/ic_launcher" /> 

     <ImageButton 
      android:id="@+id/downloadBtn" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:background="?selectableItemBackgroundBorderless" 
      android:clickable="true" 
      android:contentDescription="abc" 
      android:src="@drawable/ic_launcher" /> 
    </LinearLayout> 
</RelativeLayout> 

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

Và đừng quên để khởi tạo tất cả điều này và thiết lập tiêu đề của bạn là false để chỉ hiển thị thanh công cụ lại nút:

Hoạt động Mã

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.test); 

    Toolbar mToolBar = (Toolbar) findViewById(R.id.imagePreviewToolbar); 
    setSupportActionBar(mToolBar); 
    getSupportActionBar().setDisplayHomeAsUpEnabled(true); 
    getSupportActionBar().setDisplayShowTitleEnabled(false); 
    getSupportActionBar().setHomeButtonEnabled(true); 

} 
.210

Pics enter image description here

Hope tôi giúp bạn.

+0

Cảm ơn bạn lần nữa! Bạn sẽ kiểm tra sau hành vi của Thanh công cụ ở chế độ ngang. – xmattjus

+0

Đây là những gì đã làm cho tôi quá. Tuy nhiên, tôi không phải kết hợp AppBarLayout + Toolbar, tôi chỉ chuyển cả hai sang vị trí cuối cùng trong CoordinatorLayout. Làm việc trong cảnh quan và chân dung quá. – brianclements

+0

Làm thế nào về FrameLayout với Fragment động, nơi tôi đặt Thanh công cụ của mình? – fanjavaid

1

Make thanh công cụ như thế này:

<android.support.design.widget.AppBarLayout 
       android:id="@+id/myAppBar" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       app:elevation="0dp"...> 
    </android.support.design.widget.AppBarLayout> 

Và sau đó trong hoạt động của bạn;

findViewById(R.id.myAppBar).bringToFront(); 
Các vấn đề liên quan