如何在appbarlayout内制作带有圆角和高程的工具栏?喜欢这张照片

SAN*_*ARI 5 android android-layout android-actionbar android-toolbar

这是我尝试创建带有圆角的工具栏的代码,如图所示。

<android.support.design.widget.AppBarLayout
    android:id="@+id/appBar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="12dp"
    android:background="@android:color/transparent">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/bg_actionbar" />

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

bg_actionbar.xml

<?xml version="1.0" encoding="utf-8"?>
<shape android:shape="rectangle"
xmlns:android="http://schemas.android.com/apk/res/android" >
<solid android:color="@color/white" />
<corners android:radius="16dp" />
</shape>
Run Code Online (Sandbox Code Playgroud)

这就是我要创造的 这就是我得到的

Jay*_*mar 9

设置app:elevation="0dp"AppBarLayout

并设置android:elevation="4dp"Toolbar

并将 'android:layout_margin="4dp"' 设置为 Toolbar,这将帮助您显示阴影。

所以你的布局会是这样的

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

<android.support.v7.widget.Toolbar
    android:id="@+id/toolbar"
    android:elevation="4dp"
    android:layout_margin="4dp"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/bg_actionbar" />
Run Code Online (Sandbox Code Playgroud)