AppBarLayout с панелью инструментов не имеет тени / возвышения - PullRequest
2 голосов
/ 17 января 2020

Я пытаюсь добавить панель инструментов в свою деятельность, используя AppBarLayout, но я не могу получить какие-либо возвышения или тени на ней.

Я использую следующие макет и стили;

<!-- activity -->
<androidx.coordinatorlayout.widget.CoordinatorLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">

    <com.google.android.material.appbar.AppBarLayout
        android:id="@+id/appbar"
        style="@style/Widget.App.AppBar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fitsSystemWindows="true">

        <androidx.appcompat.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?actionBarSize"  />

    </com.google.android.material.appbar.AppBarLayout>

    <fragment
        android:id="@+id/nav_host_fragment"
        android:name="androidx.navigation.fragment.NavHostFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        app:defaultNavHost="true"
        app:navGraph="@navigation/main_graph"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

</androidx.coordinatorlayout.widget.CoordinatorLayout>
<!-- styles -->
<style name="App" parent="Theme.MaterialComponents.DayNight.NoActionBar">
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="colorSecondary">@color/colorAccent</item>
    <item name="colorSurface">@color/background</item>

    <item name="toolbarStyle">@style/Widget.App.Toolbar</item>
    <item name="android:statusBarColor">@color/background</item>
    <item name="android:windowLightStatusBar">true</item>
    <item name="android:navigationBarColor">@android:color/white</item>
    <item name="android:windowLightNavigationBar" tools:targetApi="o_mr1">true</item>
</style>

<style name="App.PopupTheme" parent="ThemeOverlay.MaterialComponents.Light">
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="colorSecondary">@color/colorAccent</item>
</style>

<style name="Widget.App" parent="@android:style/Widget.Material" />

<style name="Widget.App.AppBar" parent="@style/Widget.Design.AppBarLayout">
    <item name="android:background">@color/white</item>
    <item name="android:elevation">12dp</item>
    <item name="elevation">12dp</item>
</style>

<style name="Widget.App.Toolbar" parent="Widget.MaterialComponents.Toolbar">
    <item name="android:paddingEnd">8dp</item>
    <item name="contentInsetStartWithNavigation">64dp</item>
    <item name="popupTheme">@style/App.PopupTheme</item>
</style>

Даже без какой-либо стилизации панель инструментов отображается без тени от нее.

Используя приведенный выше код, я получаю

enter image description here

Но это должно выглядеть следующим образом

enter image description here

Я уже пробовал копировать стили из приложения Google IO с открытым исходным кодом (на втором снимке экрана) от) но это тоже не сработало.

Я использую

'com.google.android.material:material:1.2.0-alpha03' (также пробовал последнюю стабильную версию)

Заранее спасибо

...