material-components-android: Problems with BottomAppBar Elevation

Version number

Library version: 1.0.0-alpha2

Details

While trying out the all-new BottomAppBar I’ve noticed that it has no elevation, which should be present by default as per the guidelines, and even worse than that is the fact there is no way to set it manually (.setElevation(…) & .setTranslationZ(…) have no effect).

I have also analyzed the source code of the aforementioned widget and it seems like the following should be responsible for the drawing of the background shadow:

    topEdgeTreatment =
        new BottomAppBarTopEdgeTreatment(fabCradleMargin, fabCornerRadius, fabVerticalOffset);
    ShapePathModel appBarModel = new ShapePathModel();
    appBarModel.setTopEdge(topEdgeTreatment);
    materialShapeDrawable = new MaterialShapeDrawable(appBarModel);
    materialShapeDrawable.setStrokeWidth(1f /* hairline */);
    materialShapeDrawable.setShadowEnabled(true);
    materialShapeDrawable.setPaintStyle(Style.FILL);
    DrawableCompat.setTintList(materialShapeDrawable, backgroundTint);
    ViewCompat.setBackground(this, materialShapeDrawable);

while it hints at its role in the drawing of the shadow, no shadow is actually getting drawn.

I believe this is a bug as the same widget is used in the Google I/O 2018 app, where it is displayed properly (with default elevation).

Screenshots

  • My sample app

screenshot_20180513-175640 2

  • Google I/O 2018 app

screenshot_20180513-175652 2

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 7
  • Comments: 23 (5 by maintainers)

Most upvoted comments

My bad. I update the dependency

implementation ‘androidx.appcompat:appcompat:1.1.0-alpha01’ implementation ‘com.google.android.material:material:1.1.0-alpha02’

The shadow works fine now but when I set the fab to the end of bottomappbar the icons on the bottomappbar are also aligned at the end instead of the right side. It makes the icons and the fab collapsed at the end of bottomappbar

@davidlira94 still waiting for the stable release, which should have that issue addressed.

I have the same issue when using “com.android.support:design:28.0.0-alpha1”

I don’t know to enforce the elevation shadow, they brute-forced it or something or most probably they’re still using a drawable but now, setting android:elevation="any value" in BottomAppBar in xml gives an NPE as

Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void com.google.android.material.shape.MaterialShapeDrawable.setElevation(float)' on a null object reference
        at com.google.android.material.bottomappbar.BottomAppBar.setElevation(BottomAppBar.java:450)

I’ve also the latest support libraries :

 implementation 'androidx.appcompat:appcompat:1.1.0'
 implementation 'com.google.android.material:material:1.3.0-alpha01'

I want to remove the elevation completely and setting the background null as below does nothing either.

android:background="@drawable/transparent_background_bottom_navigation_view"
android:outlineAmbientShadowColor="@android:color/transparent"
android:outlineSpotShadowColor="@android:color/transparent"

Complete Log:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.app.app/com.app.app.activity.Home}: android.view.InflateException: Binary XML file line #177: Binary XML file line #177: Error inflating class <unknown>
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2793)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2864)
        at android.app.ActivityThread.-wrap12(ActivityThread.java)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1567)
        at android.os.Handler.dispatchMessage(Handler.java:105)
        at android.os.Looper.loop(Looper.java:156)
        at android.app.ActivityThread.main(ActivityThread.java:6517)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:942)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:832)
     Caused by: android.view.InflateException: Binary XML file line #177: Binary XML file line #177: Error inflating class <unknown>
     Caused by: android.view.InflateException: Binary XML file line #177: Error inflating class <unknown>
     Caused by: java.lang.reflect.InvocationTargetException
        at java.lang.reflect.Constructor.newInstance0(Native Method)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:430)
        at android.view.LayoutInflater.createView(LayoutInflater.java:656)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:798)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:738)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:869)
        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:832)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:872)
        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:832)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:872)
        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:832)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:872)
        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:832)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:518)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:426)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:377)
        at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:555)
        at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:161)
        at com.app.app.activity.Home.onCreate(Home.kt:54)
        at android.app.Activity.performCreate(Activity.java:6915)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1123)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2746)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2864)
        at android.app.ActivityThread.-wrap12(ActivityThread.java)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1567)
        at android.os.Handler.dispatchMessage(Handler.java:105)
        at android.os.Looper.loop(Looper.java:156)
        at android.app.ActivityThread.main(ActivityThread.java:6517)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:942)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:832)
     Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void com.google.android.material.shape.MaterialShapeDrawable.setElevation(float)' on a null object reference
        at com.google.android.material.bottomappbar.BottomAppBar.setElevation(BottomAppBar.java:450)
        at android.view.View.<init>(View.java:4688)
        at android.view.ViewGroup.<init>(ViewGroup.java:578)
        at android.view.ViewGroup.<init>(ViewGroup.java:574)
        at androidx.appcompat.widget.Toolbar.<init>(Toolbar.java:236)
        at com.google.android.material.bottomappbar.BottomAppBar.<init>(BottomAppBar.java:227)