0

I am setting the elevation property on my AppBarLayout & it works from api 21 to 26 but the shadow isn't shown on device, emulator running on api >= 27.
Has there been any change with AppBarLayout or elevation property?

here's how I am using the code -

<?xml version="1.0" encoding="utf-8"?>
<com.google.android.material.appbar.AppBarLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:elevation="8dp"
    app:theme="@style/ThemeOverlay.MaterialComponents.Dark">

    <androidx.appcompat.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        app:popupTheme="@style/ThemeOverlay.MaterialComponents.Light"
        app:theme="@style/ThemeOverlay.MaterialComponents.Dark.ActionBar" />

</com.google.android.material.appbar.AppBarLayout>
Darshan
  • 4,020
  • 2
  • 18
  • 49

3 Answers3

1

Try to use the app:elevation attribute with namespace as app

<?xml version="1.0" encoding="utf-8"?>
<com.google.android.material.appbar.AppBarLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:elevation="8dp"
    app:theme="@style/ThemeOverlay.MaterialComponents.Dark"/>
Aamir Khan
  • 99
  • 1
  • 5
0
  • Have you tried StateListAnimator.

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { StateListAnimator stateListAnimator = new StateListAnimator(); stateListAnimator.addState(new int[0], ObjectAnimator.ofFloat(appBarLayout, "elevation", 0.1f)); appBarLayout.setStateListAnimator(stateListAnimator); }

OR

  • Try Setting Background

android:background="@android:color/white" android:elevation="10dp"

Hope it works !

0

remove <application android:hardwareAccelerated="false"/> if exists in AndroidManifest.xml

asannov
  • 189
  • 2
  • 8