片段未获得可访问性焦点

片段未获得可访问性焦点

本文介绍了替换后片段未获得可访问性焦点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个有片段的活动.该片段正确地获得了可访问性焦点.但是,当用另一个片段替换第一个片段时,第二个片段不能自动获得焦点,我必须触摸该片段以获取焦点.

I have an activity that has a fragment. That fragment gets the accessibility focus correctly. But when a replace the first fragment with another one, the second one is not getting the focuse automatically, I have to touch the fragment to get the focus.

这是替换的方式:

val fragmentTransaction = supportFragmentManager.beginTransaction()
fragmentTransaction.replace(R.id.container, myFragment)
fragmentTransaction.commit()
container.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED)

我尝试将 android:importantForAccessibility android:clickable ="true" 添加到第二个片段(该片段未获得可访问性焦点)

I try to add the android:importantForAccessibility and the android:clickable="true" to the second fragment (the one that is not getting accessibility focus)

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/white"
    android:orientation="vertical"
    android:clickable="true"
    android:focusable="true"
    android:importantForAccessibility="yes">

    ...

</LinearLayout>

我也尝试使用添加片段,而不是用相同的结果替换.

I also try to use the add fragment instead of replace with the same result.

谢谢!

推荐答案

另一种解决方案-您可以简单地通知用户有关屏幕更改的信息.如果片段包含工具栏,则可以在显示片段时将其设置为焦点.或者您可以专注于第一个/主要合理元素.这样,它将向用户宣布一个新屏幕,它将对用户有更大的帮助.

An alternate solution - you can simply notify a user about screen change. If your fragment contains a toolbar, then you can set it focused while fragment is being displayed. or you could focus on the first/main reasonable element. In this way, It will announce a new screen to the user and it will be more helpful to users.

toolbar.requestFocus()
toolbar.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED)

这篇关于替换后片段未获得可访问性焦点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-22 14:02