How to implement android intermediate progressbar accessibility

1.4k Views Asked by At

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.

2

There are 2 best solutions below

0
On

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"
1
On

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