当设置app:elevation="0dp"时,汉堡菜单不会显示在工具栏上。

8

您好,我想要去掉工具栏下面的阴影效果。为此,我使用了“elevation”属性。 目前我的代码如下:

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

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/transparent">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"

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


    <FrameLayout
        android:id="@+id/content_frame"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />


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

输出结果如下:

在此输入图片描述

我不想要下面的阴影,所以我设置了

    app:elevation="0dp" 

将AppBarLayout的阴影去掉后,汉堡菜单消失了。

新的输出如下:

enter image description here

请问有人能告诉我如何在不隐藏/消失汉堡菜单的情况下去掉阴影吗?

1个回答

17

试试这个:

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

然后在你的活动中;

findViewById(R.id.appBar).bringToFront();

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接