4

I am trying to get the focus directly to the action button in the snackbar when the snackbar is being shown so that users are made aware that there is some action that can be performed with the alert message as shown in the snackbar. Note: this is for talkback mode. I have tried using requestFocus() and sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED); but either way the focus seems to stay in the fragment. Also I am facing a similar issue with material showcase view action button. Any tips on how to get the focus there?

Quintin Balsdon
  • 5,484
  • 10
  • 54
  • 95
Himanshu Chhabra
  • 257
  • 1
  • 2
  • 12

2 Answers2

1
  snackbar.getView().findViewById(com.google.android.material.R.id.snackbar_action).sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED);

Remember to call this after a certain delay so that accessibility get attach to snackbar widget

Amit kumar
  • 149
  • 14
0

Call snackbar.getView().requestFocus(); as your final step

This means it should come after you configure the SnackBar, after you set the action, and after you make a call to show() (regardless of the order you do those things)

If it works on Android TV, where gaining focus is like winning the lottery, it should work for you.

Abandoned Cart
  • 4,512
  • 1
  • 34
  • 41