How to make spannable text clickable with Accessibility mode on
Asked Answered
G

4

10

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);
Gelhar answered 13/2, 2017 at 14:52 Comment(6)
Please refer this link #5184145Sinasinai
i have tried that but that dose't help me.Gelhar
Did you found any answer on this issue. I am getting stuck on similar kind of issue. Let me know solution for this if you have.Phebe
@Phebe No, i did'nt find any solution to this , i am still searching for it , will update the answer as soon as ill solve it.Gelhar
I've got the same problem. Does anyone have a good solution for this?Teammate
Anybody find solution? Stuck with the same problem.Earn
E
7

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
Earthaearthborn answered 25/7, 2019 at 19:36 Comment(3)
This is the only post Google founds about that method call, would you be so kind to elaborate your answer more since I don't understand how this is supposed to work, called on a textView which has links in the string but couldn't see any difference. What is the expectation using this?Nobie
When in Accessibility mode Talkback won't read spannable string as a clickable object, therefore the user won't know there's a link to click on. Before Android X, you had to rely in work around solutions such as using URLSpan with a match IntentFilter. ViewCompat.enableAccessibleClickalbleSpanSupport comes to solve that. Documentation: developer.android.com/reference/androidx/core/view/…Earthaearthborn
I should work if you have Android X. We are using in our company's codebase.Earthaearthborn
E
0

I'm afraid there is no way in android to implement that (I had the same issue for months). the only way is using the local context menu. Looks like Talkback is trying to make the ADA users to get use to the menus using there gestures, which will fix too many issue in our dev side. There might be another way, which is creating a WebView and then add html elements which will handle everything, BUT this will be bad for the app performance :(

As mentioned here: Clickable links (Google support)

you have to access local context menu to activate any clickable span by Swiping up and then right, and then click on Links submenu.

Hope this helps :)

Expansible answered 3/6, 2019 at 17:21 Comment(2)
what about the new enableAccessibleClickableSpanSupport?Nobie
But there's no way to double tap on the text itself and open the link? You need to perform the gesture, then select links, then select the link itself? That's a lot of user actions to open a link in the text!Undershoot
E
0

Try this one, worked for me. An alternate working solution.

private void setUpBottomSheetAccessibility() {
    ViewCompat.setAccessibilityDelegate(view, new AccessibilityDelegateCompat() {

        @Override
        public void onPopulateAccessibilityEvent(View host, AccessibilityEvent event) {
            if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_LONG_CLICKED) {
                //Put your work to be done on double click;
            }
            super.onPopulateAccessibilityEvent(host, event);
        }
    });
}

Above code view is your Textview or any view. And this event work on double click.

Working fine at my end.

Enunciation answered 29/12, 2021 at 13:26 Comment(0)
N
-2

Nothing to do.Just you click the Spannable link with two finger on the screen, and one of them must be on the Spannable link. Try some times!!!

Nikos answered 11/6, 2020 at 10:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.