Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make spannable text clickable with Accessibility mode on

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.

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);
like image 354
Tushar Purohit Avatar asked Feb 13 '17 14:02

Tushar Purohit


1 Answers

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

It should work back to API 19.

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

android.useAndroidX = true
android.enableJetifier = true
like image 172
devB78 Avatar answered Sep 17 '22 12:09

devB78