简体   繁体   中英

TalkBack: Prevent Selection of Obscured View

错误的话语提示图像

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?

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); .

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)

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM