File tree Expand file tree Collapse file tree 1 file changed +22
-0
lines changed
lib/java/com/google/android/material/behavior Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -421,4 +421,26 @@ public void disableOnTouchExploration(boolean disableOnTouchExploration) {
421421 public boolean isDisabledOnTouchExploration () {
422422 return disableOnTouchExploration ;
423423 }
424+
425+ /**
426+ * A utility function to get the {@link HideViewOnScrollBehavior} associated with the {@code
427+ * view}.
428+ *
429+ * @param view The {@link View} with {@link HideViewOnScrollBehavior}.
430+ * @return The {@link HideViewOnScrollBehavior} associated with the {@code view}.
431+ */
432+ @ NonNull
433+ @ SuppressWarnings ("unchecked" )
434+ public static <V extends View > HideViewOnScrollBehavior <V > from (@ NonNull V view ) {
435+ ViewGroup .LayoutParams params = view .getLayoutParams ();
436+ if (!(params instanceof LayoutParams )) {
437+ throw new IllegalArgumentException ("The view is not a child of CoordinatorLayout" );
438+ }
439+ CoordinatorLayout .Behavior <?> behavior = ((LayoutParams ) params ).getBehavior ();
440+ if (!(behavior instanceof HideViewOnScrollBehavior )) {
441+ throw new IllegalArgumentException (
442+ "The view is not associated with HideViewOnScrollBehavior" );
443+ }
444+ return (HideViewOnScrollBehavior <V >) behavior ;
445+ }
424446}
You can’t perform that action at this time.
0 commit comments