1

I have a task to make substring as a link and open local html page in web view rather than web browser.

For example, there is a string of

"You have to accept Terms and Condition to register."

Here Terms and Condition is a substring and on click of that link I have to open html page in webview

Harsh Patel
  • 657
  • 11
  • 26

1 Answers1

2

You can do something like this:

SpannableString ss = new SpannableString("You have to accept Terms and Condition to register.");
    ClickableSpan termsClickableSpan = new ClickableSpan() {
        @Override
        public void onClick(View textView) {
            // Call the webview activity.
        }

        @Override
        public void updateDrawState(TextPaint ds) {

        }
    };
ss.setSpan(termsClickableSpan, 20, 39, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
textView.setText(ss);
textView.setMovementMethod(LinkMovementMethod.getInstance());

Here you have to use SpannableString and set the ClickableSpan to those text that you need to be clicked. Here, 2nd and 3rd parameter of setSpan method denotes the start and end of the text to be clicked.

Srijith
  • 1,695
  • 17
  • 29