David Berry
David Berry

Reputation: 41246

TalkBack: Prevent Selection of Obscured View

Bad TalkBack Image

In the image above, you can see that TalkBack has selected a label that is completely obscured. If I tap again, then the entire panel at the top will be selected (it's set as focusable) which is the desired behavior.

How can I prevent TalkBack from selecting complete (or partially) obscured views for announcement?

At a minimum, how can I force talkback to select the top/obscuring view FIRST?

Upvotes: 4

Views: 3256

Answers (3)

Thiago
Thiago

Reputation: 13302

You can add the code below, So TalkBack will ignore that view/image:

android:importantForAccessibility="no"

Updated Answer:

When the View is obscured set it to the root of the obscured this:

mainContentView.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS);

Then when you bring that view back do this:

mainContentView.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO);

Upvotes: 1

heLL0
heLL0

Reputation: 1425

Use the Layout Inspector to find this label and remove its visibility.

Per Android documentation To open the Layout Inspector, do the following:

  1. Run your app on a connected device or emulator.

  2. Click Tools > Layout Inspector.

  3. In the Choose Process dialog that appears, select the app process you want to inspect and click OK.

  4. The Layout Inspector captures a snapshot, saves it as a .li file, and opens it.

Set the visibility to GONE, programmatically or in the layout file:

android:visibility="gone"

Or

nameOfLabel.setVisibility(View.GONE)

Upvotes: 0

MobA11y
MobA11y

Reputation: 18900

So, there's not quite enough information to answer this completely. It's not clear whether your "Learn" more thing is a modal dialog, and so needs dealt with, or if it can remain on screen and interaction with the things lower in the layout should remain accessible.

Scenario 1: Let's assume that the "Learn More" dialog is a modal that should be dealt with before everything else, what you want is to use a custom AlertDialog. The Android system will then set up all of the important properties, without requiring different permissions. Ultimately what the Android OS does in this case is add a new view with TYPE_SYSTEM_ALERT, which ensures that the dialog is the only actionable thing on screen (and also only accessible!).

https://developer.android.com/guide/topics/ui/dialogs.html#CustomLayout

Scenario 2: The "Learn More" banner is not a modal. What you want to do is hide the view behind the banner. You can do this by setting view.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO);.

Upvotes: 0

Related Questions