Take this android layout XML snippet for example:
<ImageView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_weight="1"
android:padding="10dp"
app:srcCompat="@drawable/bitcoin"
android:contentDescription="@null"
android:importantForAccessibility="no"
tools:ignore="ContentDescription" />
What is the difference between android:contentDescription="@null"
and tools:ignore="ContentDescription"?
I know both of them are used to indicate that a certain non-textual element carries no meaning and is only meant for decoration. Is there an advantage of using one over the other, should I use both, is it preference, or is one considered better and newer than the other?
Also, should I use android:importantForAccessibility="no"
or is using all three attributes/properties simply overkill?
What is the difference between
android:contentDescription="@null"
andtools:ignore="ContentDescription"
?
For graphical elements, such as ImageView
and ImageButton
. If you do not set their respective android:contentDescription
XML attributes, a lint warning message will be displayed.
"Missing contentDescription attribute on image"
To suppress this lint warning message then you must use tools:ignore="ContentDescription"
in XML.
I know both of them are used to indicate that a certain non-textual element carries no meaning and is only meant for decoration. Is there an advantage of using one over the other, should I use both, is it preference, or is one considered better and newer than the other?
No, they are different from each other in term of usage, for example
<ImageView
android:layout_width="200dp"
android:layout_height="300dp"
android:id="@+id/image_user_avatar"
android:contentDescription="User avatar"
tools:ignore="ContentDescription" />
When running the app with TalkBack, it will speak "User avatar".
Should I use
android:importantForAccessibility="no"
?
If your app only supports devices running Android 4.1 (API level 16) or higher, you can set these elements' android:importantForAccessibility
XML attributes to "no"
instead of android:contentDescription="@null
.
Update
So basically tools:ignore="ContentDescription" is only for the compiler and android:contentDescription="@null" is for user user?
Yes, it is.
Also, my 'minSdk' is 14 and my 'targetSdk' is 28. Can I still set both android:importantForAccessibility="no" and android:contentDescription="@null"?
Yes, you can set both of them but if you run the app on device whose SDK below 16, android:importantForAccessibility="no"
will be ignored.
Will android:contentDescription="@null" have the same effect as android:importantForAccessibility="no" for devices running Android 4.1 or higher?
They have slightly difference.
android:contentDescription="@null"
: The view with this attribute still highlighted when users move finger on it and Accessibility Services will speak out loud dummy text such as "Button", etc.
android:importantForAccessibility="no"
: The view with this attribute is disabled by the app so it will not highlighted when users move finger on and ignored by Accessibility Services as well.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With