如何在启用“辅助功能”模式的情况下使可扩展文本可单击 [英] How to make spannable text clickable with Accessibility mode on

查看:254
本文介绍了如何在启用“辅助功能”模式的情况下使可扩展文本可单击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题说明,我需要在启用辅助功能设置的情况下运行我的应用程序,以便获得反馈意见,但是这里的问题是当我单击 TextView 时其中具有Spannable链接,则它读取全文,但不允许我单独单击该Spannable文本,同时禁用可访问性,从而使字符串可以跨多个字符串或单击链接。

I have a problem statement where i need to run my application with Accessibility setting on, to have talk back feedback, but the problem here is when i click on a TextView which have Spannable link in it, then it reads the full text but dose not allow me to click on that Spannable text separately while disabling the accessibility allows to make string multi spannable or link clickable.

这是我的代码,使 String 可点击:

here is my code to make String clickable :

SpannableString ss = new SpannableString("Android is a Software stack");
ClickableSpan clickableSpan = new ClickableSpan() {
    @Override
    public void onClick(View textView) {
        startActivity(new Intent(MyActivity.this, NextActivity.class));
    }
    @Override
    public void updateDrawState(TextPaint ds) {
            super.updateDrawState(ds);
            ds.setUnderlineText(false);
        }
};
ss.setSpan(clickableSpan, 22, 27, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

TextView textView = (TextView) findViewById(R.id.hello);
textView.setText(ss);
textView.setMovementMethod(LinkMovementMethod.getInstance());
textView.setHighlightColor(Color.TRANSPARENT);


推荐答案

如果您使用的是Android X库,您应该可以

If you are using Android X library you should be able to handle accessibility and clickable spannable strings by:

ViewCompat.enableAccessibleClickableSpanSupport(yourView);

还要确保您拥有最新的依赖项:

Also make sure you have the latest dependency:

com.android.support:appcompat-v7:28.0.0

它应该可以重新使用API​​ 19。

注意:要启用 Android X 库,请转至您的 gradle.properties 并添加以下行:

Note: To enable Android X library go to your gradle.properties and add these lines:

android.useAndroidX = true
android.enableJetifier = true

这篇关于如何在启用“辅助功能”模式的情况下使可扩展文本可单击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆