16

I have edittext for entering first name when creating account and its hint is "Jane"(as first name). I also want to have content description on this edittext for accessibility saying "first name". When I set both hint and content description warning pops up "Do not set both contentDescription and hint: the contentDescription will mask the hint" and this is fine, it's just that content description doesn't mask hint. When I turn on TalkBack it still reads hint and not content description.

Could anyone help me with this. Thnx.

Damir
  • 1,092
  • 4
  • 18
  • 32

2 Answers2

4

From what I understand, android:hint is meant as a placeholder for text in TextViews (and its subclasses) as long as they do not display any text, whereas android:contentDescription is meant as alternative textual description for non-textual content (images...). Therefore I'd set hint on the EditText only.

Hans Hohenfeld
  • 1,729
  • 11
  • 14
  • 2
    I just realized if I select input type textPassword it will read content description and not hint, but I don't understand why this property has affect on accessibility. Clearly I can't use this input type on all edit texts – Damir Oct 11 '13 at 12:28
  • @Damir although I wasn't aware of that, it makes kind of sense. An EditText with inputType textPassword is more or less non-textual content, therefore it needs a contentDescription. As far as I understand, hint is only read by accessibility software in case textual content is currently not present in a TextView and otherwise the text is read. I guess no accessibility software would read the text of an input type textPaswort EditText, when something was already entered, therefore it won't read the hint, but the contentDescription in both cases (text entered or not). – Hans Hohenfeld Oct 11 '13 at 14:03
  • "As far as I understand, hint is only read by accessibility software in case textual content is currently not present in a TextView and otherwise the text is read." - I thought the same thing but this is not the case, hint is read even if I add content description while warning in Eclipse states differently. "Do not set both contentDescription and hint: the contentDescription will mask the hint" – Damir Oct 14 '13 at 07:48
  • @Damir but is hint read, when no contenDescription is available on a TextView/EditText, and it doesn't hold any text? – Hans Hohenfeld Oct 14 '13 at 14:58
  • 4
    Sorry for my late response, yes hint is read when no contetDescription is available, but I want contentDescription to be read(if it is available) not the hint. – Damir Oct 17 '13 at 12:54
-1

I encountered the same problem and solved it by setting the hint to null when the accessibility service is enabled. Cause when it is enabled the user probably won't need the hint.

private void setAccessibility()
{
   if (isExploreByTouchEnabled())
   {         
      firstName.setHint(null);
      firstName.setContentDescription("first name");
   }
}

public boolean isExploreByTouchEnabled()
{
   AccessibilityManager am = (AccessibilityManager) getContext().getSystemService(ACCESSIBILITY_SERVICE);
   boolean isAccessibilityEnabled = am.isEnabled();
   boolean isExploreByTouchEnabled = am.isTouchExplorationEnabled();
   return isAccessibilityEnabled && isExploreByTouchEnabled;
}
Wirling
  • 4,810
  • 3
  • 48
  • 78