简体   繁体   中英

Restrict focus of talkback on notification bar in android

I have an android device in which I set the talkback turned on. Now whenever I restart/reboot the device at that time talkback directly gets focus on notification bar and starts speech out of "syncing sim contacts", "USB debugging connected" etc. Is there any way to either stop focusing on notification bar when device gets restarted/rebooted or keep talkback silent during this specific speech out. Any help will be appreciable.

There are questionable usages for what you want to do.

Perhaps you should post your UI/UX and why you'd want to restrict this default TalkBack behavior. TalkBack users are generally (but not limited to) visually-impaired people, and they greatly rely on the audio cues provided by the service. Attempting to out smart it is generally a bad idea. This doesn't mean there aren't valid use-cases, hence why the next paragraph shows you how to move the focus where you may want it.

If you still want to ensure the accessibility service focuses a specific portion of your UI when you open a fragment or activity, then add some helper functions like:

fun View.requestAccessibilityFocus() {
    performAccessibilityAction(AccessibilityNodeInfo.ACTION_ACCESSIBILITY_FOCUS, null)
    sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED)
}

And then in onCreate or onViewCreated request it:

import androidx.core.view.doOnLayout

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
   super.onViewCreated(view, savedInstanceState)

   val theViewYouWantToFocus = ... //findViewById or use ViewBinding

   theViewYouWantToFocus.doOnLayout {
       it.requestAccessibilityFocus()
   }
}

The reason for doOnLayout is to let the android layout system to finish the layout pass and to make sure that the accessibility system gets a finalized picture of your layout hierarchy before it attempts to focus a particular view for the purposes of talkback. Your mileage may vary.

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