2929import android .content .res .TypedArray ;
3030import android .os .Build ;
3131import android .os .Build .VERSION_CODES ;
32+ import android .os .Bundle ;
3233import android .os .Handler ;
3334import android .os .Looper ;
3435import android .os .Message ;
4041import com .google .android .material .behavior .SwipeDismissBehavior ;
4142import com .google .android .material .internal .ThemeEnforcement ;
4243import android .support .design .widget .CoordinatorLayout ;
44+ import android .support .v4 .view .AccessibilityDelegateCompat ;
4345import android .support .v4 .view .ViewCompat ;
4446import android .support .v4 .view .WindowInsetsCompat ;
47+ import android .support .v4 .view .accessibility .AccessibilityManagerCompat ;
48+ import android .support .v4 .view .accessibility .AccessibilityManagerCompat .TouchExplorationStateChangeListener ;
49+ import android .support .v4 .view .accessibility .AccessibilityNodeInfoCompat ;
4550import android .util .AttributeSet ;
4651import android .view .Gravity ;
4752import android .view .LayoutInflater ;
@@ -278,6 +283,28 @@ public WindowInsetsCompat onApplyWindowInsets(View v, WindowInsetsCompat insets)
278283 }
279284 });
280285
286+ // Handle accessibility events
287+ ViewCompat .setAccessibilityDelegate (
288+ view ,
289+ new AccessibilityDelegateCompat () {
290+ @ Override
291+ public void onInitializeAccessibilityNodeInfo (
292+ View host , AccessibilityNodeInfoCompat info ) {
293+ super .onInitializeAccessibilityNodeInfo (host , info );
294+ info .addAction (AccessibilityNodeInfoCompat .ACTION_DISMISS );
295+ info .setDismissable (true );
296+ }
297+
298+ @ Override
299+ public boolean performAccessibilityAction (View host , int action , Bundle args ) {
300+ if (action == AccessibilityNodeInfoCompat .ACTION_DISMISS ) {
301+ dismiss ();
302+ return true ;
303+ }
304+ return super .performAccessibilityAction (host , action , args );
305+ }
306+ });
307+
281308 accessibilityManager =
282309 (AccessibilityManager ) context .getSystemService (Context .ACCESSIBILITY_SERVICE );
283310 }
@@ -678,6 +705,10 @@ boolean shouldAnimate() {
678705 /** @hide */
679706 @ RestrictTo (LIBRARY_GROUP )
680707 protected static class SnackbarBaseLayout extends FrameLayout {
708+
709+ private final AccessibilityManager accessibilityManager ;
710+ private final TouchExplorationStateChangeListener touchExplorationStateChangeListener ;
711+
681712 private BaseTransientBottomBar .OnLayoutChangeListener onLayoutChangeListener ;
682713 private BaseTransientBottomBar .OnAttachStateChangeListener onAttachStateChangeListener ;
683714
@@ -694,7 +725,24 @@ protected SnackbarBaseLayout(Context context, AttributeSet attrs) {
694725 }
695726 a .recycle ();
696727
697- setFocusable (true );
728+ accessibilityManager =
729+ (AccessibilityManager ) context .getSystemService (Context .ACCESSIBILITY_SERVICE );
730+ touchExplorationStateChangeListener =
731+ new TouchExplorationStateChangeListener () {
732+ @ Override
733+ public void onTouchExplorationStateChanged (boolean enabled ) {
734+ setClickableOrFocusableBasedOnAccessibility (enabled );
735+ }
736+ };
737+
738+ AccessibilityManagerCompat .addTouchExplorationStateChangeListener (
739+ accessibilityManager , touchExplorationStateChangeListener );
740+ setClickableOrFocusableBasedOnAccessibility (accessibilityManager .isTouchExplorationEnabled ());
741+ }
742+
743+ private void setClickableOrFocusableBasedOnAccessibility (boolean touchExplorationEnabled ) {
744+ setClickable (!touchExplorationEnabled );
745+ setFocusable (touchExplorationEnabled );
698746 }
699747
700748 @ Override
@@ -721,6 +769,9 @@ protected void onDetachedFromWindow() {
721769 if (onAttachStateChangeListener != null ) {
722770 onAttachStateChangeListener .onViewDetachedFromWindow (this );
723771 }
772+
773+ AccessibilityManagerCompat .removeTouchExplorationStateChangeListener (
774+ accessibilityManager , touchExplorationStateChangeListener );
724775 }
725776
726777 void setOnLayoutChangeListener (
0 commit comments