Toolbar not showing elevation in Android 9, API 28

℡╲_俬逩灬. 提交于 2019-12-13 05:06:01

问题


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:


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>



来源:https://stackoverflow.com/questions/56818304/toolbar-not-showing-elevation-in-android-9-api-28

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!