How to implement android intermediate progressbar accessibility

ぐ巨炮叔叔 提交于 2021-02-10 14:47:51

问题


I would like to announce the loading text on an android intermediate progressbar. I want to output something like this for disabled people who are using talkback service on the Android device when an intermediate progressbar is loading.

  • File is loading.
  • File is fetching.
  • File is converting.
  • File is loaded.

I checked around google and found that I could use:

1) announceForAccessibility on progressbar view. (Not working in my case, only works when I load it with a Handler)

My code

override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
    }

    override fun onResume() {
        super.onResume()
        val progressbar: ProgressBar = findViewById(R.id.testProgressBar)
        // progressbar.announceForAccessibility("My name is Neo "); // not working
        Handler().postDelayed(object : Runnable {
            override fun run() {
                progressbar.announceForAccessibility("My name is Neo ");
            }
        }, 1000)

    }

Do you guys have any other suggestion to solve this kind of problem? I wonder how people got working at so many places https://www.programcreek.com/java-api-examples/?class=android.view.View&method=announceForAccessibility

Thanks for your help.


回答1:


You could try a polite android:accessibilityLiveRegion, which would ensure that TalkBack does not interrupt something already being announced:

<ProgressBar 
    android:id="@+id/testProgressBar"
    …
    android:accessibilityLiveRegion="polite" />

More here: Using a Live Region




回答2:


Make your progressbar focusable and then send custom content description based on your requirement. Talkback will handle that for you.

public void showProgresSBarWithCustomDescription(val contentDesc) {
    progressBar.contentDescription = contentDesc
    progressBar.visibility = View.VISIBLE
}

//Add following properties to progressbar

            android:focusable="true"
            android:focusableInTouchMode="true"
            android:importantForAccessibility="yes"


来源:https://stackoverflow.com/questions/54281265/how-to-implement-android-intermediate-progressbar-accessibility

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!