Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 411
SANDIP CHAUDHARI Avatar asked Jul 26 '18 10:07

SANDIP CHAUDHARI


1 Answers

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

like image 75
Jay Thummar Avatar answered Nov 05 '22 11:11

Jay Thummar