删除特定片段的工具栏高程

Emm*_*nce 7 android elevation toolbar

如何将Elevation设置为0或为我的特定片段禁用它NavigationDrawer?可能以编程方式或主题?

toolbar.setElevation(0) 似乎不起作用.

这不是我的onNavigationItemSelected工作,海拔不会改变:

if (item.getItemId() == R.id.drawer_menu_account) {
    if (getSupportActionBar() != null) {
        getSupportActionBar().setElevation(0);
    }
} else {
    if (getSupportActionBar() != null) {
        getSupportActionBar().setElevation(8);
    }
}
Run Code Online (Sandbox Code Playgroud)

我的协调员布局有工具栏

<?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=".activity.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>

<FrameLayout
    android:id="@+id/content_frame"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginTop="?attr/actionBarSize" />

<android.support.design.widget.FloatingActionButton
    android:id="@+id/fab"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|end"
    android:layout_margin="@dimen/fab_margin"
    android:src="@drawable/ic_add_24dp" />

</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)



已解决 - 感谢Amir!在我的工作中使用它onNavigationItemSelected

if (android.os.Build.VERSION.SDK_INT >= 21) {
    if (item.getItemId() == R.id.drawer_menu_account) {
         appBar.setElevation(0);
    } else {
         appBar.setElevation(8);
    }
}
Run Code Online (Sandbox Code Playgroud)

Vij*_*jay 0

要删除工具栏中的阴影,请使用

app:elevation="0"在 AppBarLayout xml 中或

在java中使用mAppBarLayout.setTargetElevation(0)

这对我有用。