2016-02-29 32 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