How to make links among other text focusable for accessibility
Asked Answered
J

2

11

I have a CheckedTextBox whose text is made up of two SpannableStrings, one of which is a URLSpan.

My question is, how do I make so that a user can move the accessibility focus through each span, eventually focusing on the URLspan itself? setMovementMethod and setLinksClickable doesn't seem to work for me.

SpannableStringBuilder builder = new SpannableStringBuilder();

SpannableString label = new SpannableString(getString(R.string.label));
label.setSpan(new ForegroundColorSpan(getResources().getColor(R.color.text_color_primary)), 0, label.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
builder.append(label);

SpannableString link = new SpannableString(getString(R.string.link);
link.setSpan(new URLSpan(mUrl), 0, link.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
builder.append(link);
builder.append(".");

mCheckedTextBox.setText(builder);

//The following two methods do not work for what I'm trying to accomplish:
mCheckedTextBox.setMovementMethod(LinkMovementMethod.getInstance());
mCheckedTextBox.setLinksClickable(true);

I've checked on the Android Accessibility Help documentation and it seems that as long as the user hears a chime and can see the link in the local context menu, it is sufficient. However, I wanted to see if I can go that extra mile to enable the user to scroll and focus to the link portion of the text. https://support.google.com/accessibility/android/answer/6378148?hl=en

Any help would be appreciated.

Jud answered 18/7, 2016 at 19:45 Comment(1)
Not supported by the platform. You would basically need to write your own TextView to support this via AccessibilityNodeProvider.Gawky
K
1

This isn't supported by the platform. Android's own documentation directs users to open the Local Context Menu to access links in TextViews: https://support.google.com/accessibility/android/answer/6378148?hl=en

Kazbek answered 6/11, 2019 at 0:3 Comment(0)
W
0

Maybe this can be the easiest solution..it worked for me.

textView.setOnClickListener(new View.OnClickListener() {
  @Override
  public void onClick(View v) {
      ClassroomLog.log(TAG, "Textview Click listener ");
      if (textView.getSelectionStart() == -1 && textView.getSelectionEnd() == -1){
          // Perform your action here
      }
  }
});
Wow answered 1/8, 2019 at 7:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.