简体   繁体   中英

How to make links among other text focusable for accessibility

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.

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
      }
  }
});

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM