8

I am working on a large project, where we use TextViews to show text as well as a hint.

When using talkback (accessibility), I have noticed that the hint on a TextView is read twice.

Also even when there is text in the TextView, the hint will still be read.

When I use an EditText instead, only the second problem persists (text entered, hint is still read). This seems to be normal (but confusing) Android-behaviour, since Google-Apps like the PlayStore do this as well.

But why is the TextView reading the hint twice, while an EditText is not?


PS: I am aware of the possibility to switch from TextView to EditText, but since we are using custom views as well that heavily depend on TextView, this is not a feasible option.

I am also aware of using label for, but I am more interested in the technical background why TextView reads the hint twice.

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:hint="test"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent"/>

Accessibility is read twice

hamena314
  • 2,969
  • 5
  • 30
  • 57
  • This is printing in a toast? – Ankita Jul 18 '18 at 07:53
  • @Ankita: No, in the talkback-developer options you can activate a visual representation of what the talkback-reader is saying: `Settings -> Accessibility -> Talkback -> Settings -> Developer settings -> Display speech output`. Easy to find, isnt it? – hamena314 Jul 18 '18 at 07:56
  • how can we start talkback on emulator? – Ankita Jul 18 '18 at 10:01
  • @Ankita https://stackoverflow.com/questions/37098548/testing-accessibility-on-emulated-device-marshmallow ... but my problem is not limited to the emulator – hamena314 Jul 18 '18 at 10:34
  • Did you find a solution for the same? I too face the same issue. – Anju Dec 01 '20 at 11:31
  • To this date (1.st December 2020) I have not found a solution. – hamena314 Dec 01 '20 at 12:41
  • You could try to set a `contentDescription`! Maybe that will work? I would try and change the text `TEST` above in the ToolbarLayout, to be sure that it is not the text that you hear the first time, although I do not think that is the problem. – 476rick Dec 02 '20 at 09:59
  • @hamena314 what is the name of this activity in the AndroidManifest.xml? – 476rick Mar 09 '21 at 19:54
  • @ hamena31 did you get solution ? – Jithish P N Dec 28 '22 at 17:39

2 Answers2

1

I reported it as https://issuetracker.google.com/issues/274627677

I found a workaround that seems to work as expected:

view.accessibilityDelegate = object : AccessibilityDelegate() {
    override fun onInitializeAccessibilityNodeInfo(host: View, info: AccessibilityNodeInfo) {
        super.onInitializeAccessibilityNodeInfo(host, info)
        info.hintText = ""
    }
}
arekolek
  • 9,128
  • 3
  • 58
  • 79
0

It's announcing twice because you're setting the 'hint' to the TextView since it reads its own text as a content description, and 'hint' is being used as text when there is no text set. I think it's not being handled correctly in the TextView.

GSutey
  • 136
  • 6