Android 启用辅助功能时,使超链接可单击
我正在使用可访问性和通话/画外音使应用程序可访问 如何使链接具有可点击性 使用以下方法使Android 启用辅助功能时,使超链接可单击,android,android-accessibility,Android,Android Accessibility,我正在使用可访问性和通话/画外音使应用程序可访问 如何使链接具有可点击性 使用以下方法使超链接可在文本视图中单击 /** * This method creates the link and associates the ClickableSpan to it. * Once the ClickableSpan is clicked, it will call the * ClickableSpanListener.performAction */ public static void
超链接
可在文本视图
中单击
/**
* This method creates the link and associates the ClickableSpan to it.
* Once the ClickableSpan is clicked, it will call the
* ClickableSpanListener.performAction
*/
public static void makeLinkClickable(
final ClickableSpanListener clickableSpanListener,
final SpannableStringBuilder strBuilder,
final URLSpan span) {
final int start = strBuilder.getSpanStart(span);
final int end = strBuilder.getSpanEnd(span);
final int flags = strBuilder.getSpanFlags(span);
//get the String that is used as the link
final char[] characters = new char[end - start];
strBuilder.getChars(start, end, characters, 0);
final ClickableSpan clickable = new ClickableSpan() {
public void onClick(final View view) {
clickableSpanListener.performAction(span.getURL(), new String(characters));
}
};
strBuilder.setSpan(clickable, start, end, flags);
strBuilder.removeSpan(span);
}
/**
* This method takes in a String that contains at least one link defined by HTML <a></a> tags.
* A link will be created in the String and added to the TextView.
* The link will become clickable and the action (onClick) is defined by the
* ClickableSpanListener.
*/
public static void setTextViewHTML(
final ClickableSpanListener clickableSpanListener,
final TextView text,
final String html) {
final CharSequence sequence = Html.fromHtml(html);
final SpannableStringBuilder strBuilder = new SpannableStringBuilder(sequence);
final URLSpan[] urls = strBuilder.getSpans(0, sequence.length(), URLSpan.class);
for (final URLSpan span : urls) {
makeLinkClickable(clickableSpanListener, strBuilder, span);
}
text.setText(strBuilder);
text.setMovementMethod(LinkMovementMethod.getInstance());
}
/**
* This is the interface that should be implemented by classes to define the action
* that will occur when a clickablespan is clicked
*/
public interface ClickableSpanListener {
void performAction(String url, String linkText);
}
setTextViewHTML(
this,
txtTermsPrivacy,
getString(R.string.terms_condition_privacy_policy)
);
/**
*此方法创建链接并将ClickableSpan与之关联。
*单击ClickableSpan后,它将调用
*ClickableSpanListener.performation
*/
公共静态void makeLinkClickable(
最终可点击span监听器可点击span监听器,
最终跨度由StringBuilder strBuilder、,
最终URLSpan){
final int start=strBuilder.getSpanStart(span);
final int end=strBuilder.getSpanEnd(span);
final int flags=strBuilder.getSpanFlags(span);
//获取用作链接的字符串
最终字符[]个字符=新字符[结束-开始];
strBuilder.getChars(开始、结束、字符,0);
最终可点击span clickable=新可点击span(){
公共void onClick(最终视图){
clickableSpanListener.performAction(span.getURL(),新字符串(字符));
}
};
strBuilder.setSpan(可单击、开始、结束、标志);
strBuilder.removeSpan(span);
}
/**
*此方法接收一个字符串,该字符串至少包含一个由HTML定义的链接,我已尝试使用,但似乎不起作用。如中所述,用户需要通过对讲
手势访问本地上下文菜单
(默认手势为向上滑动然后向右
)激活TextView
链接
事实上,TextView
小部件上任何可点击的span
都可以通过其上下文菜单通过TalkBack
激活,甚至连不打开浏览器的链接也可以。您执行的performAction
可能会显示Toast
消息,用户可以通过上下文菜单激活
我用Android 8.1中的talkback7.3.0
和Android:autoLink=“web”
对它进行了测试。这两项工作都如预期的那样
<TextView
android:id="@+id/myTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:autoLink="web"
android:text="This is a TextView with link to StackOverflow: http://www.stackoverflow.com, and to Android Documentation: https://developer.android.com." />
另一方面:
<string name="permissions_request_agreement_label">I agree to the Optus Privacy Policy</string>
<string name="permissions_request_agreement_url">https://www.optus.com.au/about/legal/privacy/telco-services</string>
我同意Optus隐私政策
https://www.optus.com.au/about/legal/privacy/telco-services
<string name="permissions_request_agreement_label">I agree to the Optus Privacy Policy</string>
<string name="permissions_request_agreement_url">https://www.optus.com.au/about/legal/privacy/telco-services</string>