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) {
271
271
* version from androidx when it's available.
272
272
*/
273
273
@ 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
+ }
275
278
if (Build .VERSION .SDK_INT >= 18 ) {
276
279
return new ViewOverlayApi18 (view );
277
280
}
@@ -288,6 +291,10 @@ public static ViewGroup getContentView(@Nullable View view) {
288
291
}
289
292
if (parent .getParent () instanceof ViewGroup ) {
290
293
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 ;
291
298
}
292
299
}
293
300
return null ;
Original file line number Diff line number Diff line change 67
67
import com .google .android .material .drawable .DrawableUtils ;
68
68
import com .google .android .material .internal .DescendantOffsetUtils ;
69
69
import com .google .android .material .internal .ThemeEnforcement ;
70
+ import com .google .android .material .internal .ViewOverlayImpl ;
70
71
import com .google .android .material .internal .ViewUtils ;
71
72
import com .google .android .material .resources .MaterialResources ;
72
73
import com .google .android .material .shape .CornerFamily ;
@@ -1291,8 +1292,11 @@ protected void onDetachedFromWindow() {
1291
1292
}
1292
1293
1293
1294
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
+ }
1296
1300
}
1297
1301
1298
1302
super .onDetachedFromWindow ();
Original file line number Diff line number Diff line change @@ -339,7 +339,10 @@ public void setLayoutMargin(@Px int layoutMargin) {
339
339
*
340
340
* @see #detachView(View)
341
341
*/
342
- public void setRelativeToView (@ NonNull View view ) {
342
+ public void setRelativeToView (@ Nullable View view ) {
343
+ if (view == null ) {
344
+ return ;
345
+ }
343
346
updateLocationOnScreen (view );
344
347
// Listen for changes that indicate the view has moved so the location can be updated
345
348
view .addOnLayoutChangeListener (attachedViewLayoutChangeListener );
@@ -350,7 +353,10 @@ public void setRelativeToView(@NonNull View view) {
350
353
*
351
354
* @see #setRelativeToView(View)
352
355
*/
353
- public void detachView (@ NonNull View view ) {
356
+ public void detachView (@ Nullable View view ) {
357
+ if (view == null ) {
358
+ return ;
359
+ }
354
360
view .removeOnLayoutChangeListener (attachedViewLayoutChangeListener );
355
361
}
356
362
You can’t perform that action at this time.
0 commit comments