Toolbar not showing elevation in Android 9, API 28

2019-08-19 12:03发布

In my app, the Toolbar is not showing shadow at its bottom, my target API is from Android 6 M to Android 9 P, I am testing my app on device having Android 9 Pie.

There is a same question here but no answer.

toolbar.xml

<androidx.appcompat.widget.Toolbar
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:elevation="4dp">
</androidx.appcompat.widget.Toolbar>

activity_main.xml

<androidx.drawerlayout.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:openDrawer="start" >
    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
        <include layout="@layout/toolbar"/>
        <FrameLayout
            android:id="@+id/fragment_main"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
    </LinearLayout>
    <include layout="@layout/navigation_drawer" />
</androidx.drawerlayout.widget.DrawerLayout>

1条回答
爷、活的狠高调
2楼-- · 2019-08-19 12:56

You can implement like this -

<android.support.design.widget.AppBarLayout
           android:id="@+id/appBarLayout"
           android:layout_width="match_parent"
           android:layout_height="wrap_content"
           app:elevation="0dp">

     <androidx.appcompat.widget.Toolbar
  xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/toolbar"
   android:layout_width="match_parent"
   android:layout_height="?attr/actionBarSize"
   android:elevation="4dp">
 </androidx.appcompat.widget.Toolbar>

查看更多
登录 后发表回答