Tuesday 28 April 2020

Accessibility : Useful Accessibility Functions

When Talkback is announcing the element , it must be focused that announcing element .

  • ImportantForAccessibility :
In android , the elements can also hide from accessibility :

Auto (0): This is the default, it is the system that decides.
Yes (1): The view is important for accessibility. For example, it can receive the TalkBack focus.
No (2): The view is not important for accessibility. It does not trigger accessibility events and is therefore ignored by accessibility services such as TalkBack.
NoHideDescendants (4): The view is not important for accessibility, nor are its children views.

 <TextView
        android:id="@+id/textShow"
        android:importantForAccessibility="yes"
        android:text="Title" />

    <TextView
        android:id="@+id/textHide"
        android:importantForAccessibility="no"
        android:text="Should Not Announce" />

    <TextView
        android:id="@+id/textDesc"
        android:importantForAccessibility="yes"
        android:text="Description" />

Here , @+id/textHide , will not get focused & not announced . Remaining two will announce.

For more info :
https://developer.android.com/reference/android/view/View#attr_android:importantForAccessibility


  • LabelFor :
Specifies the id of a view for which this view serves as a label for accessibility purposes. For example, a TextView before an EditText in the UI usually specifies what information is contained in the EditText. Hence, the TextView is a label for the EditText.

    <TextView
        android:id="@+id/textName"
        android:text="Enter Name"
        android:labelFor="@+id/editTextTextPersonName"
       />

    <EditText
        android:id="@+id/editTextTextPersonName"
        android:inputType="textPersonName" />




  • Reordering Elements :
This helps to set a logical focus order of the elements inside a view-group , there are 2 main attributes which helps to set the order : 

  1. android:accessibilityTraversalBefore on a view to specify what item this should come before .
  2. android:accessibilityTraversalAfter on a view to specify what item this should come after .


  <TextView
        android:id="@+id/textShow"
        android:text="Title" />

    <TextView
        android:id="@+id/textLast"
        android:text="Should Announce in last"
        android:accessibilityTraversalAfter="@id/textDesc"/>

    <TextView
        android:id="@+id/textDesc"
        android:text="Description"
        android:accessibilityTraversalAfter="@id/textShow"/>

Demo :



  • Changing Content :
When any view's content is subject to change dynamically and should in this case notify the Accessibility API which can be done by setAccessibilityLiveRegion method that takes a mode parameter for the live region. There are 3 modes:

ACCESSIBILITY_LIVE_REGION_NONE: This is the default for most views , not live region.

ACCESSIBILITY_LIVE_REGION_POLITE: When a change occurs, talkback are triggered by the changes. they have lower priority than system by default announcements.

ACCESSIBILITY_LIVE_REGION_ASSERTIVE: When a change occurs,  are triggered by the changes, having the highest priority and are immediately announce.
For example : Any list is having filter button , and  data of the list is changing by applying the filters on it , in that case , this attribute can be useful , because list is changing again and again.


  • AnnouncementForAccessibility : 
When announceForAccessibility() is called, Android will give an audible announcement for those using a screen reader, and do nothing if an accessibility tool is not in use. You can use this to inform the user that the value has been incremented.

amount.announceForAccessibility(getString(R.string.count))



These are many more attributes , which can be used for accessibility implementation.

No comments:

Post a Comment

Advanced Kotlin Coroutines : Introduction

 Hi,  Today I am unwraping the topic in Kotin world i.e. Coroutine . If you want to get started with Kotlin coroutine and ease your daily de...