2016-02-29 52 views
7

我想通过在上添加<item name="android:statusBarColor">@android:color/transparent</item>到v21/styles.xml来使状态栏变为透明,但我一直在应用栏上方留下阴影,是否可以将其删除?如何删除应用程序栏上方的阴影?

编辑: 好的我认为解决方案是移动应用程序栏占据状态栏空间并扩展应用程序栏的其他dp以匹配它的大小,所以我的问题是,是否可以移动或扩展应用程序酒吧高度向上?

activity_search.xml

<android.support.design.widget.AppBarLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:theme="@style/MyMaterialTheme.AppBarOverlay"> 

    <android.support.v7.widget.Toolbar 
      android:id="@+id/toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:background="?attr/colorPrimary" 
      app:popupTheme="@style/MyMaterialTheme.PopupOverlay"/> 

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

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

enter image description here

+0

化妆仰角= 0 –

+0

高于或低于?如果上面那么它的colorPrimaryDark – Bhargav

+0

@Bhargav在应用栏上方,这在状态栏上可见。 – brettbrdls

回答

15

我相信这个问题是指向同一个问题 Android appbarlayout elevation appears in status bar

可能的解决方案:

你的根布局应该有android:fitsSystemWindows="true"在任何时候,否则你的UI不会落后状态栏绘制。

现在包裹AppBarLayout内的另一个CoordinatorLayout具有

android:fitsSystemWindows="false"

这将防止阴影溢出到状态栏中。

+0

最后,非常感谢! – brettbrdls

+0

@brettbrdls,我不认为这个解决方案现在可以在AppCompat v24.0.0中工作 –

+0

如果我的根布局是CoordinatorLayout会怎么样?我尝试在另一个布局中包装它,但在这种情况下,状态栏是白色的,而它应该是红色的(colorPrimaryDark) – Chapz

5

添加海拔0dp到AppBarLayout

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

但是,是否有可能只删除应用程序栏上方的阴影而不是下面的部分? – brettbrdls

5

以您想要的状态栏颜色调用以下方法中的onCreate

public void changeStatusBarColor(String hexColor) 
    { 
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { 
     Window window = getWindow(); 
     window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); 
     window.setStatusBarColor(Color.parseColor("#AD2525")); 
    } 
} 

XML

<?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" 
tools:context="com.example.bharath.myapplication.MainActivity"> 

<android.support.design.widget.AppBarLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:theme="@style/AppTheme.AppBarOverlay"> 

    <android.support.v7.widget.Toolbar 
     android:id="@+id/toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="?attr/actionBarSize" 
     android:background="?attr/colorPrimary" 
     app:popupTheme="@style/AppTheme.PopupOverlay" /> 

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

<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="#AD2525" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior"> 
    <!-- 
    Other views 
    --> 

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

Result

+1

只有有效的答案。其他建议的应用程序:海拔=“0dp”击败对象。谢谢 – Tony