How to make toolbar with rounded corners and elevation inside appbarlayout? Like this picture

10,731

Set app:elevation="0dp" in AppBarLayout

And set android:elevation="4dp" to Toolbar

And also set 'android:layout_margin="4dp"' to Toolbar which will help you to show shadow.

So your layout will be like this

<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" />

Share:
10,731
SANDIP CHAUDHARI
Author by

SANDIP CHAUDHARI

Updated on July 25, 2022

Comments

  • SANDIP CHAUDHARI
    SANDIP CHAUDHARI almost 2 years

    This is my code that I try to create toolbar with rounded corners shown in picture.

    <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>
    

    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>
    

    This what I'm trying to create This is what I'm getting

  • SANDIP CHAUDHARI
    SANDIP CHAUDHARI almost 6 years
    Thanks for your support, I also tried this, but it works in Api 21 and higher only, what about below api 21?
  • Jay Thummar
    Jay Thummar almost 6 years
    If you are considering those devices then you have to create a image bg with this kind of shadow in photo shop and set as background