Skip to content

Commit 3f43a2a

Browse files
raajkumarscketcham
authored andcommitted
Updated FloatingActionButton to support dark theme elevation overlays.
PiperOrigin-RevId: 239611087
1 parent 0425d3b commit 3f43a2a

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

lib/java/com/google/android/material/floatingactionbutton/FloatingActionButton.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import android.graphics.Rect;
3434
import android.graphics.drawable.Drawable;
3535
import android.os.Build;
36+
import android.os.Build.VERSION_CODES;
3637
import android.os.Bundle;
3738
import android.os.Parcelable;
3839
import androidx.annotation.AnimatorRes;
@@ -44,6 +45,7 @@
4445
import androidx.annotation.NonNull;
4546
import androidx.annotation.Nullable;
4647
import androidx.annotation.Px;
48+
import androidx.annotation.RequiresApi;
4749
import androidx.annotation.RestrictTo;
4850
import androidx.annotation.VisibleForTesting;
4951
import com.google.android.material.animation.MotionSpec;
@@ -1163,6 +1165,13 @@ private void offsetIfNeeded(CoordinatorLayout parent, FloatingActionButton fab)
11631165
}
11641166
}
11651167

1168+
@RequiresApi(VERSION_CODES.LOLLIPOP)
1169+
@Override
1170+
public void setElevation(float elevation) {
1171+
super.setElevation(elevation);
1172+
getImpl().updateShapeElevation(elevation);
1173+
}
1174+
11661175
/**
11671176
* Returns the backward compatible elevation of the FloatingActionButton.
11681177
*

lib/java/com/google/android/material/floatingactionbutton/FloatingActionButtonImpl.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ void setBackgroundDrawable(
189189
}
190190

191191
shapeDrawable.setShadowColor(Color.DKGRAY);
192+
shapeDrawable.initializeElevationOverlay(view.getContext());
192193

193194
// Now we created a mask Drawable which will be used for touch feedback.
194195
MaterialShapeDrawable touchFeedbackShape = createShapeDrawable();
@@ -360,7 +361,7 @@ void onElevationsChanged(
360361
updateShapeElevation(elevation);
361362
}
362363

363-
private void updateShapeElevation(float elevation) {
364+
void updateShapeElevation(float elevation) {
364365
if (shapeDrawable != null) {
365366
shapeDrawable.setElevation(elevation);
366367
}

lib/java/com/google/android/material/floatingactionbutton/FloatingActionButtonImplLollipop.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ void setBackgroundDrawable(
6565
if (backgroundTintMode != null) {
6666
shapeDrawable.setTintMode(backgroundTintMode);
6767
}
68+
shapeDrawable.initializeElevationOverlay(view.getContext());
6869

6970
final Drawable rippleContent;
7071
if (borderWidth > 0) {
@@ -99,6 +100,7 @@ void onElevationsChanged(
99100
final float elevation,
100101
final float hoveredFocusedTranslationZ,
101102
final float pressedTranslationZ) {
103+
102104
if (Build.VERSION.SDK_INT == VERSION_CODES.LOLLIPOP) {
103105
// Animations produce NPE in version 21. Bluntly set the values instead in
104106
// #onDrawableStateChanged (matching the logic in the animations below).

0 commit comments

Comments
 (0)