Android - prevent TalkBack from announcing TextView title aloud
Solution 1
I was trying to do the same today, and was able to set an 'empty'
contentDescription on a TextView
like so (using a non-breaking whitespace):
decorativeTextView.setContentDescription("\u00A0");
now TalkBack
doesn't say anything for that TextView
.
but I agree with Nick about leaving the label as readable in your case, because hint is only read for empty EditTexts
.
Solution 2
Since API 16, Android introduced the following:
android:importantForAccessibility="no"
or
setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO)
Which allows developers to disable talkback all together for certain views.
http://developer.android.com/reference/android/view/View.html
Solution 3
For better backwards compatibility:
ViewCompat.setImportantForAccessibility(
decorativeTextView,
ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_NO);
Solution 4
Why do you not want the TextView to speak "forename"? It is being used as a label for the EditText. Once the user has entered some text the hint "enter your forename here" would no longer be spoken - as far as I know - so the TextView given the user some context for the EditText.
Similarly the announcement of "editbox" gives the user the role of the EditText control. While "form field" might be better it would not be the same behavior as in other apps and in the OS.
Solution 5
I had a similar problem. I eventually solved it by using the setAccessibilityDelegate
method and overriding View.AccessibilityDelegate's
performAccessibilityAction
method.
try this:
View forename = findViewById(R.id.forename);
forename.setAccessibilityDelegate(new AccessibilityDelegate() {
public boolean performAccessibilityAction (View host, int action, Bundle args){
return true;
}
});
Alex
Updated on July 05, 2022Comments
-
Alex almost 2 years
I am developing an accessible android application where people would be using Explore by Touch and TalkBack accessibility services to use my application.
This is my Android XML code:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/LinearLayout" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <TextView android:id="@+id/forename" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="20dip" android:layout_marginLeft="15dip" android:textSize="20sp" android:text="@string/forenameText" android:contentDescription="@null"/> <EditText android:id="@+id/EditTextForename" android:layout_width="285dp" android:layout_height="65dp" android:layout_marginTop="10dip" android:layout_marginLeft="15dip" android:hint="@string/forenameHint" android:inputType="textPersonName" android:lines="1" android:singleLine="true" android:textSize="20sp" > </EditText> </LinearLayout>
strings.xml
<string name="forenameText">Forename</string> <string name="forenameHint">Enter your forename here</string>
TextView displays the title "Forename" and EditText allows me to enter some details in the form field. The problem I have is that when I drag my finger across the screen by using Explore by Touch, TalkBack picks up the title of the TextView and announces it aloud as "Forename". I want the TextView to only display text and not provide any audible feedback.
I have set contentDescription to @null as you can see from the code above, but TalkBack still announces "Forename" when my finger is located over the TextView.
I have also tried setting contentDescription in my Java class:
TextView forename=(TextView)findViewById(R.id.forename); forename.setContentDescription("");
However, I still get the same problem. Is there any other way to set contentDescription to null/empty and prevent TalkBack from announcing it aloud?
Java code:
public class MainActivity extends Activity{ protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); View forename = findViewById(R.id.forename); forename.setAccessibilityDelegate(new AccessibilityDelegate() { public boolean performAccessibilityAction (View host, int action, Bundle args){ return true; } }); } }
-
Alex about 11 yearsThank you for your reply, mmaloon. I have applied your solution to my program but unfortunately TalkBack still announces "forename" aloud. I've updated my original post with Java code that I currently have. My current workaround is to use ImageViews instead of TextViews as by default they don't provide any audible feedback.
-
Alex about 11 yearsI also have another question regarding my EditText form field. I have a "hint" attribute there that reads a string called "forenameHint". That string contains the following text: "Enter your forename here". When I use Explore by Touch and drag my finger across the form field, TalkBack announces "EditBox Enter your forename here". Is there a way to prevent it from announcing "EditBox" before every string in the hint attribute? Or maybe change it to something more user friendly like "Form field: Enter your forename here"? Thanks in advance
-
Alex about 11 yearsThat's a good point. The reason I don't want the TextView to provide any audible feedback is because I have more than one TextViews and EditText fields in the application. The problem I have is that when I point at one of the TextViews, TalkBack announces all the TextViews aloud. So even if I point at the TextView that is located at the very bottom of the screen, TalkBack announces all the TextViews one by one. I have yet to figure out what causes this problem.
-
Alex about 11 yearsThis fixed the problem. Thank you so much for your help! Please see my comment under the Nick's post. I have another problem that I'm trying to solve now.
-
Alex about 11 yearssorry I meant when I drag my finger across a particular TextView on the screen, all the TextViews are announced aloud one by one by the screen reader.
-
salfon about 11 yearsre. that new issue in your comment: i don't get that behavior with your originally posted layout, with some duplicate TextView-EditText pairs to test. do you see the accessibility focus box around an individual TextField you're touching when this happens? I've found that if the container (eg LinearLayout) gets accessibilityfocus instead (the yellowbox), the read-only children would all be read, and are not treated as individually 'touchable' - so you might think you've touched the TextField, but the event (and focus) actually went through to parent...
-
Matt about 10 yearsMy "answer" mentions API specific updates, this solution works for older versions of Android as well! Thanks!
-
Herrbert74 over 9 yearsAnd with revision 22 it's now in the v4 support library. developer.android.com/tools/support-library/index.html
-
akash89 about 8 yearsHelpul answer ! :)
-
ChrisCM about 7 yearsAre you text views collected in a listView or other container where the container has the importantForAccessibility property specifically set to "yes"?
-
azizbekian almost 7 yearsThis technique is especially helpful in
RecyclerView
: I've applied this to theviewHolder.itemView
. Pay attention, view must be focusable. -
harikrishnan almost 6 yearsHi Salfon, did you face this scenario... stackoverflow.com/questions/52215042/…