sam_k
sam_k

Reputation: 6023

How to implement android intermediate progressbar accessibility

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.

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.

Upvotes: 1

Views: 1557

Answers (2)

Nav Singh
Nav Singh

Reputation: 1

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"

Upvotes: 0

Jon Gibbins
Jon Gibbins

Reputation: 1086

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

Upvotes: 2

Related Questions