简体   繁体   中英

Accessibility (TalkBack) : How to make a particular view focussed automatically, just after the complete fragment loads?

  • When I click on a certain option, while the talkback feature is on, the selection of the view remains the same in the next fragment also.
  • Either the selection or focus the view in the first fragment should be removed or the another view in the next fragment should be focussed.
  • Currently I am using the following code :

     await Task.Delay(TimeSpan.FromSeconds(1)); view.SendAccessibilityEvent(Android.Views.Accessibility.EventTypes.ViewFocused); 
  • But is this a good practice because I am adding delay in the system.

您可以像下面的onActivityCreated方法中的视图一样执行可访问性操作

view.performAccessibilityAction(AccessibilityNodeInfo.ACTION_ACCESSIBILITY_FOCUS, null);

You can use this if your fragment/activity have indivual view:

<view_id>.requestFocus()
<view_id>.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED)

if you have RecyclerView and you want to focus at the topmost item :

 <recyclerView_id>.post {
            val child = this.getChildAt(0)
            child?.let {
                it.requestFocus()
                it.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED)
            }
        }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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