Skip to content

Commit 8059ac1

Browse files
tadfisherdsn5ft
authored andcommitted
[NavigationView] Fix obtaining Activity in setupInsetScrimsListener
Resolves #1628 Resolves #1627 GIT_ORIGIN_REV_ID=4042d13c8326144184e46795b217b9172b6552ad PiperOrigin-RevId: 327446397 (cherry picked from commit a6a750b)
1 parent 194a0aa commit 8059ac1

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

lib/java/com/google/android/material/navigation/NavigationView.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
import android.view.MenuItem;
6060
import android.view.View;
6161
import android.view.ViewTreeObserver.OnGlobalLayoutListener;
62+
import com.google.android.material.internal.ContextUtils;
6263
import com.google.android.material.internal.NavigationMenu;
6364
import com.google.android.material.internal.NavigationMenuPresenter;
6465
import com.google.android.material.internal.ScrimInsetsFrameLayout;
@@ -680,13 +681,12 @@ public void onGlobalLayout() {
680681
presenter.setBehindStatusBar(isBehindStatusBar);
681682
setDrawTopInsetForeground(isBehindStatusBar);
682683

683-
Context context = getContext();
684-
if (context instanceof Activity && VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) {
684+
Activity activity = ContextUtils.getActivity(getContext());
685+
if (activity != null && VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) {
685686
boolean isBehindSystemNav =
686-
((Activity) context).findViewById(android.R.id.content).getHeight()
687-
== getHeight();
687+
activity.findViewById(android.R.id.content).getHeight() == getHeight();
688688
boolean hasNonZeroAlpha =
689-
Color.alpha(((Activity) context).getWindow().getNavigationBarColor()) != 0;
689+
Color.alpha(activity.getWindow().getNavigationBarColor()) != 0;
690690

691691
setDrawBottomInsetForeground(isBehindSystemNav && hasNonZeroAlpha);
692692
}

0 commit comments

Comments
 (0)