2016-06-12 140 views
5

我想disable the shadow below a transparent AppBarLayout/Toolbar.这里的布局:AppBarLayout海拔隐藏工具栏

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

我已经与

app:elevation="0dp" 

getSupportActionBar().setElevation(0); 

尝试,但使the UP arrow invisible。我也尝试删除AppBarLayout并只使用工具栏,但问题仍然存在。

任何人都有解决方案吗?


编辑:

更换AppBarLayout +工具栏的组合与此代码:

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

部分固定的问题。现在,只有当设备处于横向模式时,工具栏才会变得不可见! Android Studio布局编辑器向我展示了两种方向上的工具栏都很好,所以我不知道问题会出在哪里。

+0

你好,你尝试过app:elevation =“0dp”的工具栏。尝试用xml而不是编程。 @xmattjus 试试这个链接http://stackoverflow.com/a/31492804/2736849 –

+0

@MFaisalHyder感谢您的链接,部分解决了问题..现在工具栏变得只有在横向模式下才可见。这发生了有或没有海拔属性集。 – xmattjus

+0

不替换布局,这次使用AppBarLayout中的ToolBar尝试应用程序:ele ...属性到应用程序栏布局而不是工具栏让我知道。还有一件事尝试在不同的设备/模拟器上 –

回答

11

经过一番尝试,我确实发现ToolBar应该是这种情况下的最后一个视图如果它将是第一个,那么它将会重叠它的视图,因为它的高度设置为match_parent,所以在布局中尝试这种方式。

布局

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

而且不要忘了初始化这一切,您的标题设置为false,只显示工具栏后退按钮:

活动代码

@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); 

} 

照片管理 enter image description here

希望我帮你。

+0

再次感谢!稍后检查横向模式下的工具栏行为。 – xmattjus

+0

这对我来说也是如此。我不必将AppBarLayout + Toolbar结合起来,但是我只是将它们移动到了CoordinatorLayout的最后一个位置。也在风景和肖像工作。 – brianclements

+0

如何在动态片段的FrameLayout中,我把我的工具栏? – fanjavaid

1

制作工具栏是这样的:

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

而在这之后你的活动;

findViewById(R.id.myAppBar).bringToFront();