File tree Expand file tree Collapse file tree 3 files changed +22
-5
lines changed
lib/java/com/google/android/material Expand file tree Collapse file tree 3 files changed +22
-5
lines changed Original file line number Diff line number Diff line change @@ -271,7 +271,10 @@ public static float getParentAbsoluteElevation(@NonNull View view) {
271271 * version from androidx when it's available.
272272 */
273273 @ Nullable
274- public static ViewOverlayImpl getOverlay (@ NonNull View view ) {
274+ public static ViewOverlayImpl getOverlay (@ Nullable View view ) {
275+ if (view == null ) {
276+ return null ;
277+ }
275278 if (Build .VERSION .SDK_INT >= 18 ) {
276279 return new ViewOverlayApi18 (view );
277280 }
@@ -288,6 +291,10 @@ public static ViewGroup getContentView(@Nullable View view) {
288291 }
289292 if (parent .getParent () instanceof ViewGroup ) {
290293 parent = (ViewGroup ) parent .getParent ();
294+ } else if (parent .getParent () == null ) {
295+ // If android.R.id.content has not been found and parent has no more parents to search,
296+ // exit.
297+ return null ;
291298 }
292299 }
293300 return null ;
Original file line number Diff line number Diff line change 6767import com .google .android .material .drawable .DrawableUtils ;
6868import com .google .android .material .internal .DescendantOffsetUtils ;
6969import com .google .android .material .internal .ThemeEnforcement ;
70+ import com .google .android .material .internal .ViewOverlayImpl ;
7071import com .google .android .material .internal .ViewUtils ;
7172import com .google .android .material .resources .MaterialResources ;
7273import com .google .android .material .shape .CornerFamily ;
@@ -1291,8 +1292,11 @@ protected void onDetachedFromWindow() {
12911292 }
12921293
12931294 for (TooltipDrawable label : labels ) {
1294- ViewUtils .getContentViewOverlay (this ).remove (label );
1295- label .detachView (ViewUtils .getContentView (this ));
1295+ ViewOverlayImpl contentViewOverlay = ViewUtils .getContentViewOverlay (this );
1296+ if (contentViewOverlay != null ) {
1297+ contentViewOverlay .remove (label );
1298+ label .detachView (ViewUtils .getContentView (this ));
1299+ }
12961300 }
12971301
12981302 super .onDetachedFromWindow ();
Original file line number Diff line number Diff line change @@ -339,7 +339,10 @@ public void setLayoutMargin(@Px int layoutMargin) {
339339 *
340340 * @see #detachView(View)
341341 */
342- public void setRelativeToView (@ NonNull View view ) {
342+ public void setRelativeToView (@ Nullable View view ) {
343+ if (view == null ) {
344+ return ;
345+ }
343346 updateLocationOnScreen (view );
344347 // Listen for changes that indicate the view has moved so the location can be updated
345348 view .addOnLayoutChangeListener (attachedViewLayoutChangeListener );
@@ -350,7 +353,10 @@ public void setRelativeToView(@NonNull View view) {
350353 *
351354 * @see #setRelativeToView(View)
352355 */
353- public void detachView (@ NonNull View view ) {
356+ public void detachView (@ Nullable View view ) {
357+ if (view == null ) {
358+ return ;
359+ }
354360 view .removeOnLayoutChangeListener (attachedViewLayoutChangeListener );
355361 }
356362
You can’t perform that action at this time.
0 commit comments