2016-11-23 122 views
1

我不能刪除AppBarLayout下面的陰影,我用下面的代碼刪除AppBarLayout下面陰影

應用:在這兩個AppBarLayout和工具欄海拔=「0dp」

,但它不是爲我工作。任何人都可以幫助我解決這個問題。 enter image description here

+0

樣品CDE ...... – nzala

+0

集應用程式:ELE vation =「0dp」 – nzala

+0

namespace xmlns:app =「http://schemas.android.com/apk/res-auto」而不是android一個 – nzala

回答

0

你應該爲工具欄設置高度爲0

<android.support.design.widget.AppBarLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/appbar" 
    android:layout_width="match_parent" 
    android:layout_height="?attr/actionBarSize" 
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" 
    android:fitsSystemWindows="true" 
    app:elevation="0dp"> 

    <android.support.v7.widget.Toolbar 
     xmlns:app="http://schemas.android.com/apk/res-auto" 
     android:id="@+id/toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     app:popupTheme="@style/ThemeOverlay.AppCompat.Light" 
     app:elevation="0dp" /> 

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

我相信這個問題是指向同一個問題的Android appbarlayout擡高出現在狀態欄中

可能的解決方案: 你的根佈局應具備的android :fitsSystemWindows =「true」,否則你的UI不會在狀態欄後面繪製。

現在包裹AppBarLayout另一CoordinatorLayout具有

android:fitsSystemWindows="false". 

這將防止陰影溢出到狀態欄裏面。

添加海拔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"> 
0

添加一個id AppBarLayout。例如android:id=「@+id/mAppBarLayout」 您的活動內(例如MainActivity.java)接收機類

創建一個新變量

private AppBarLayout mAppBarLayout; 

內onCreate方法添加以下線 -

mAppBarLayout=(AppBarLayout)findViewById(R.id.mAppBarLayout); 

現在,添加以下行去除海拔 -

mAppBarLayout.setElevation(0); 

/

您可以設置自己的活動樣式這樣的:

<!-- Your main theme with ActionBar shadow. --> 
<style name="MyAppTheme" parent="android:Theme.Holo.Light"> 
    .... 
</style> 

<!-- Theme without ActionBar shadow (inherits main theme) --> 
<style name="MyNoActionBarShadowTheme" parent="MyAppTheme"> 
    <item name="windowContentOverlay">@null</item> 
    <item name="android:windowContentOverlay">@null</item> 
</style> 

所以的Manifest.xml可以爲所有活動設置不同的風格:

<!-- Activity with ActionBar shadow --> 
<activity 
    android:name=".ShadowActivity" 
    android:theme="@style/MyAppTheme"/> 

<!-- Activity without ActionBar shadow --> 
<activity 
    android:name=".NoShadowActivity" 
    android:theme="@style/MyNoActionBarShadowTheme"/> 

或者你也可以設置編程右主題在onCreate()方法:

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    setTheme(R.style.MyNoActionBarShadowTheme); 
    super.onCreate(savedInstanceState); 

    //... 
}