0

Here is my xml code: ```

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
                                                 xmlns:app="http://schemas.android.com/apk/res-auto"
                                                 xmlns:tools="http://schemas.android.com/tools"
                                                 android:layout_width="match_parent"
                                                 android:layout_height="match_parent"
                                                 tools:context="xxxxxxxxx">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppThemeMD.NoActionBar.AppBarOverlay">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="@color/white"
            app:theme="@style/AppThemeBase"/>

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

    <include layout="@layout/content_vehicle_info"/>
</android.support.design.widget.CoordinatorLayout>

```

1.When I run my app.I Can't see shadow of Toolbar. enter image description here

2.But when I switch to another app,then switch back to my app.The shadow appeared. enter image description here enter image description here

Anyway to show shadow default?thx!

And here is my phone: Huawei 6x,Android7.0

Fan Applelin
  • 746
  • 1
  • 6
  • 16

3 Answers3

1

put this in your code (onCreate() )

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    // Call some material design APIs here
    toolbar.setElevation(3) 
} 
Karim
  • 322
  • 1
  • 10
1

add this in your AndroidManifest.xml

<application
  ...
  android:hardwareAccelerated="true">

and add this in your toobar.xml :

android:clipToPadding="false"
Karim
  • 322
  • 1
  • 10
0

You should add android:elevation = "4dp" to your Toolbar to make it elevated always as in:

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/AppThemeMD.NoActionBar.AppBarOverlay">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:elevation = "4dp"
        android:layout_height="?attr/actionBarSize"
        android:background="@color/white"
        app:theme="@style/AppThemeBase"/>

</android.support.design.widget.AppBarLayout>
Tomasz Dzieniak
  • 2,765
  • 3
  • 24
  • 42
Rajan Kali
  • 12,627
  • 3
  • 25
  • 37