Skip to content

Commit

Permalink
[NavigationView] Fix obtaining Activity in setupInsetScrimsListener
Browse files Browse the repository at this point in the history
Resolves #1628
Resolves #1627

GIT_ORIGIN_REV_ID=4042d13c8326144184e46795b217b9172b6552ad
PiperOrigin-RevId: 327446397

(cherry picked from commit a6a750b)
  • Loading branch information
tadfisher authored and dsn5ft committed Aug 28, 2020
1 parent 194a0aa commit 8059ac1
Showing 1 changed file with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
import android.view.MenuItem;
import android.view.View;
import android.view.ViewTreeObserver.OnGlobalLayoutListener;
import com.google.android.material.internal.ContextUtils;
import com.google.android.material.internal.NavigationMenu;
import com.google.android.material.internal.NavigationMenuPresenter;
import com.google.android.material.internal.ScrimInsetsFrameLayout;
Expand Down Expand Up @@ -680,13 +681,12 @@ public void onGlobalLayout() {
presenter.setBehindStatusBar(isBehindStatusBar);
setDrawTopInsetForeground(isBehindStatusBar);

Context context = getContext();
if (context instanceof Activity && VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) {
Activity activity = ContextUtils.getActivity(getContext());
if (activity != null && VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) {
boolean isBehindSystemNav =
((Activity) context).findViewById(android.R.id.content).getHeight()
== getHeight();
activity.findViewById(android.R.id.content).getHeight() == getHeight();
boolean hasNonZeroAlpha =
Color.alpha(((Activity) context).getWindow().getNavigationBarColor()) != 0;
Color.alpha(activity.getWindow().getNavigationBarColor()) != 0;

setDrawBottomInsetForeground(isBehindSystemNav && hasNonZeroAlpha);
}
Expand Down

0 comments on commit 8059ac1

Please sign in to comment.