Android:我无法删除工具栏上的高程/阴影

Android:我无法删除工具栏上的高程/阴影

问题描述:

我想从我的工具栏中删除API 21及更高版本的高程和阴影效果.以下是我尝试过的内容

Hi i would like to remove the elevation and shadow effect from my toolbar for API 21 and greater. Below is what i have tried

setSupportActionBar(mToolbar);
        getSupportActionBar().setDisplayShowTitleEnabled(false);
        getSupportActionBar().setElevation(0);

我的XML工具栏.我试图将海拔高度设置为0dp

My Toolbar in XML. I have tried to set elevation to 0dp

<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/colorPrimary"
    android:minHeight="?attr/actionBarSize"
    android:elevation="0dp"
    android:theme="@style/ToolbarStyle"
    app:theme="@style/ToolbarStyle"
    >

如果有帮助,这就是ToolbarStyle

And this is ToolbarStyle if it helps

<style name="ToolbarStyle" parent="ThemeOverlay.AppCompat.Dark">
    <item name="colorControlNormal">@android:color/white</item>
</style>

在v21样式中尝试了以下内容.结果还是一样

<style name="ToolbarStyle" parent="ThemeOverlay.AppCompat.Dark">
    <item name="colorControlNormal">@android:color/white</item>
    <item name="android:elevation">0dp</item>
</style>

工具栏在我的布局中的位置

android.support.v4.widget.DrawerLayout 

    xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/drawer_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <android.support.design.widget.CoordinatorLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <android.support.design.widget.AppBarLayout
                android:id="@+id/appBarLayout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

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

您可以轻松完成此操作.不要从布局中删除android.support.design.widget.AppBarLayout,而是向其中添加属性app:elevation="0dp".您的最终布局将是:

You can do that with an easy step. Don't remove the android.support.design.widget.AppBarLayout from your layout, instead add the attribute app:elevation="0dp" to it. Your final layout will be:

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