5

I have a TextView and an EditText. The TextView uses android:labelFor="@+id/EditTextId";

The EditText also has a hint that represents and example of input, that I only want to be visible for the users that do not use TalkBack, and not be read by the TalkBack.

android:contentDescription="Mandatory field" android:hint="Example of input"

The TalkBack would usually read (how I want it to work):

"Mandatory field, Edit Box for Text View"

but instead, reads:

"Example of input, Edit Box for Text View"

Victor Motogna
  • 731
  • 1
  • 12
  • 22

1 Answers1

4

This was possible by doing:

View.AccessibilityDelegate accessibilityDelegate = new View.AccessibilityDelegate() {
            @Override
            public void onInitializeAccessibilityNodeInfo(View v, AccessibilityNodeInfo info) {
                super.onInitializeAccessibilityNodeInfo(v, info);
                info.setText("Mandatory field");
            }
        };

        myEditTex.setAccessibilityDelegate(accessibilityDelegate);

This way, the accessibility TalkBack will read: "Mandatory field " + "Edit box for " + the TextView that has android:labelFor

Victor Motogna
  • 731
  • 1
  • 12
  • 22
  • Victor, this did work but I noticed that it goes back to hint after you add text into the edit text. I am guessing maybe one of the other delegate methods need to be messed with? you ever run into this (basically tap ET when empty, it is correct, add text then retap and it reads the hint). – Eggman87 Aug 05 '18 at 18:45
  • Victor, this messed up with hint. So to make hint working, you need to assign hintText on info object otherwise talkback miss hint text. info.hintText = "Your hint" – Harminder Singh Aug 06 '21 at 09:54