简体   繁体   English

Android - 如何清除可访问性焦点

[英]Android - how to clear accessibility focus

I would like to clear accessibility focus.我想清除可访问性焦点。 But in my case it is not easy as object that currently has focus is not accessible in the scope, so I cannot call on it clearAccessibilityFocus().但就我而言,这并不容易,因为当前具有焦点的对象在范围内不可访问,因此我无法调用它 clearAccessibilityFocus()。 In this moment I request focus on other object, that I have access to and then clear focus, but it is not good solution.在这一刻我请求关注其他对象,我可以访问然后清除焦点,但这不是一个好的解决方案。 Can you help me with that?你能帮我解决这个问题吗?

You can use你可以使用

view.performAccessibilityAction(
            AccessibilityNodeInfo.ACTION_CLEAR_ACCESSIBILITY_FOCUS, null);

to clear the accessibility focus.清除可访问性焦点。

我想你可以去:

myView.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUS_CLEARED);

You can call this on view.您可以在视图中调用它。

setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS);

I was having a problem where accessibility was leaked on the fragment which was added on top of other fragment.我遇到了一个问题,即添加在其他片段之上的片段上的可访问性被泄露。 so onCreateView() of the second fragment所以第二个片段的 onCreateView()

container.getFocusedChild().setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS);

There are two possible situations.有两种可能的情况。 If you need to remove focus from real view then you can act like this:如果您需要从真实视图中移除焦点,那么您可以这样做:

view.performAccessibilityAction(
    AccessibilityNodeInfo.ACTION_CLEAR_ACCESSIBILITY_FOCUS, 
    null
)

But if you need to remove focus from virtual view then you should do something like this:但是,如果您需要从虚拟视图中移除焦点,那么您应该执行以下操作:

view.accessibilityNodeProvider?.performAction(
    virtualViewId,
    AccessibilityNodeInfoCompat.ACTION_CLEAR_ACCESSIBILITY_FOCUS,
    null
)

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

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