简体   繁体   English

当快餐栏显示启用触摸模式时,无法关注快餐栏中的操作按钮

[英]Unable to get focus on the action button in snackbar when the snackbar is shown with touch mode enabled

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); 我尝试过使用requestFocus()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? 关于如何获得焦点的任何提示?

Call snackbar.getView().requestFocus(); 调用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) 这意味着它应该在您配置SnackBar之后,在您设置动作之后,以及在调用show() (无论您执行这些操作的顺序如何)

If it works on Android TV, where gaining focus is like winning the lottery, it should work for you. 如果它适用于Android TV,那么获得焦点就像赢得彩票一样,它应该适合你。

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

请记住在一定延迟后调用此方法,以便将可访问性附加到snackbar小部件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM