Skip to content

Commit c7a0adf

Browse files
pekingmedsn5ft
authored andcommittedAug 4, 2023
[AppBarLayout] Added getMaterialShapeBackground() to return a MaterialShapeDrawable object of the background (non-lifted layer).
PiperOrigin-RevId: 553531357
1 parent 720998d commit c7a0adf

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed
 

‎lib/java/com/google/android/material/appbar/AppBarLayout.java

+15-5
Original file line numberDiff line numberDiff line change
@@ -284,8 +284,8 @@ public AppBarLayout(@NonNull Context context, @Nullable AttributeSet attrs, int
284284
if (a.hasValue(R.styleable.AppBarLayout_expanded)) {
285285
setExpanded(
286286
a.getBoolean(R.styleable.AppBarLayout_expanded, false),
287-
/* animate */ false,
288-
/* force */ false);
287+
/* animate= */ false,
288+
/* force= */ false);
289289
}
290290

291291
if (VERSION.SDK_INT >= 21 && a.hasValue(R.styleable.AppBarLayout_elevation)) {
@@ -677,6 +677,15 @@ public CoordinatorLayout.Behavior<AppBarLayout> getBehavior() {
677677
return behavior;
678678
}
679679

680+
@Nullable
681+
public MaterialShapeDrawable getMaterialShapeBackground() {
682+
Drawable background = getBackground();
683+
if (background instanceof LayerDrawable) {
684+
background = ((LayerDrawable) background).getDrawable(0);
685+
}
686+
return background instanceof MaterialShapeDrawable ? (MaterialShapeDrawable) background : null;
687+
}
688+
680689
@RequiresApi(VERSION_CODES.LOLLIPOP)
681690
@Override
682691
public void setElevation(float elevation) {
@@ -1035,11 +1044,12 @@ boolean setLiftedState(boolean lifted, boolean force) {
10351044
}
10361045

10371046
private boolean isLiftOnScrollCompatibleBackground() {
1038-
if (getBackground() instanceof MaterialShapeDrawable) {
1047+
Drawable background = getBackground();
1048+
if (background instanceof MaterialShapeDrawable) {
10391049
return true;
10401050
}
1041-
if (getBackground() instanceof LayerDrawable) {
1042-
LayerDrawable layerBackground = (LayerDrawable) getBackground();
1051+
if (background instanceof LayerDrawable) {
1052+
LayerDrawable layerBackground = (LayerDrawable) background;
10431053
if (layerBackground.getNumberOfLayers() == 2
10441054
&& layerBackground.getDrawable(0) instanceof MaterialShapeDrawable
10451055
&& layerBackground.getDrawable(1) instanceof MaterialShapeDrawable) {

0 commit comments

Comments
 (0)
Please sign in to comment.