Skip to content

Commit

Permalink
[AppBarLayout] Added getMaterialShapeBackground() to return a Materia…
Browse files Browse the repository at this point in the history
…lShapeDrawable object of the background (non-lifted layer).

PiperOrigin-RevId: 553531357
  • Loading branch information
pekingme authored and dsn5ft committed Aug 4, 2023
1 parent 720998d commit c7a0adf
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions lib/java/com/google/android/material/appbar/AppBarLayout.java
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,8 @@ public AppBarLayout(@NonNull Context context, @Nullable AttributeSet attrs, int
if (a.hasValue(R.styleable.AppBarLayout_expanded)) {
setExpanded(
a.getBoolean(R.styleable.AppBarLayout_expanded, false),
/* animate */ false,
/* force */ false);
/* animate= */ false,
/* force= */ false);
}

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

@Nullable
public MaterialShapeDrawable getMaterialShapeBackground() {
Drawable background = getBackground();
if (background instanceof LayerDrawable) {
background = ((LayerDrawable) background).getDrawable(0);
}
return background instanceof MaterialShapeDrawable ? (MaterialShapeDrawable) background : null;
}

@RequiresApi(VERSION_CODES.LOLLIPOP)
@Override
public void setElevation(float elevation) {
Expand Down Expand Up @@ -1035,11 +1044,12 @@ boolean setLiftedState(boolean lifted, boolean force) {
}

private boolean isLiftOnScrollCompatibleBackground() {
if (getBackground() instanceof MaterialShapeDrawable) {
Drawable background = getBackground();
if (background instanceof MaterialShapeDrawable) {
return true;
}
if (getBackground() instanceof LayerDrawable) {
LayerDrawable layerBackground = (LayerDrawable) getBackground();
if (background instanceof LayerDrawable) {
LayerDrawable layerBackground = (LayerDrawable) background;
if (layerBackground.getNumberOfLayers() == 2
&& layerBackground.getDrawable(0) instanceof MaterialShapeDrawable
&& layerBackground.getDrawable(1) instanceof MaterialShapeDrawable) {
Expand Down

0 comments on commit c7a0adf

Please sign in to comment.