Home > Blockchain >  Material Button won't cast white elevation shadow on Android 11
Material Button won't cast white elevation shadow on Android 11

Time:02-14

I have a Material Button (from Google's Material Components) which can cast black shadow normally. But when I change the shadow color, it won't appear at all. Here's the button's XML portion :

   <com.google.android.material.button.MaterialButton
           android:id="@ id/next"
           android:layout_width="match_parent"
           android:layout_height="wrap_content"
           android:layout_marginTop="@dimen/margin_activity_horizontal"
           android:enabled="false"
           android:elevation="8dp"
           android:layout_margin="16dp"
           android:text="@string/setup_next"
           app:layout_constraintBottom_toBottomOf="parent"
           app:layout_constraintTop_toBottomOf="@id/nickname_entry_wrapper"
           app:layout_constraintLeft_toLeftOf="parent"
           app:layout_constraintRight_toRightOf="parent"
           tools:enabled="true"
           android:textSize="18sp"
           android:textColor="#000000"
           android:backgroundTint="#FFFFFF"
           android:fontFamily="@font/poppins_semibold"
           android:paddingVertical="12dp"
           android:outlineAmbientShadowColor="#FFFFFFFF"
           android:outlineSpotShadowColor="#FFFFFFFF"
           android:outlineProvider="background"
           android:translationZ="8dp"
           />

As you can see, outlineAmbientShadowColor and outlineSpotShadowColor are supposed to change the shadow color that results from elevation and Z translation, right ? I tried adding both elevation and Z translation at once but nothing works, the button still has 0 shadow.

The button is a child view of a Constraint Layout that has a black background. As you can see, I even tried using different values for outlineProvider such as bounds or paddedBounds, yet..nothing.

If anyone has experience with these outline attributes, I'd love to have this solved. The problem isn't specific to Android 11 only, I am just saying that I am using Android 11 for testing, since those outline attributes are only available on Android versions later than Oreo.

CodePudding user response:

As Mike M. has mentioned in the comment, those attributes don't really change the color, they just add a little 'tint'.

If you wanna use material buttons with more features, you should take a look at this library :

Github Repo: Carbon by ZieIony

It should fulfill the required objective (casting white shadows) successfully and without issues on all Android APIs.

  • Related