如何去掉工具栏周围的边框?

7
在我的应用程序中,我使用了一个工具栏,但是它似乎有一些边框,我想要去掉它们: enter image description here 并且我是这样创建的:
<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="wrap_content"
        android:gravity="center"
        android:layout_gravity="center"
        android:minHeight="?attr/actionBarSize"/>

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

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

我这样使用它:

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <include
        layout="@layout/app_bar_main_light"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />
</LinearLayout>

我从未找到指定此边框的属性或样式。

3个回答

8

我尝试了不使用AppBarLayout,它是可以工作的。只需直接使用Toolbar,不要使用AppBarLayout。


是的,对我也有效。你知道AppBarLayout中是什么造成了这个“阴影”吗? - Axl
@Axl 抱歉,我不知道。但是你可以在Playstore应用程序的搜索栏中看到相同的布局,你可以尝试让它变得像那样漂亮。 - joyl
是的,它可以工作,但只适用于Lollipop版本之后的设备。对于Lollipop版本之前的设备,应该包括AppBarLayout。 - Dinesh Neupane

1
如果@joyl的答案有效,但是您仍然不希望删除您的AppBarLayout,则可以在AppBarLayout中将elevation设置为0,如下所示:
<com.google.android.material.appbar.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:elevation="0dp">

0

这是我的解决方案。

android:stateListAnimator="@null"

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