Sunday 26 February 2017

How to set specific part of the text as clickable and make it as an action or link - Android



SpannableString policySpan= new SpannableString("Check this link Privacy Policy");
policySpan.setSpan(new ClickableSpan() {
    @Override
    public void onClick(View textView) {
        startActivity(new Intent(CurrentActivity.this, NextActivity.class));
    }
    @Override
    public void updateDrawState(TextPaint tpaint) {
            super.updateDrawState(tpaint);
            tpaint.setUnderlineText(true);
        }
}, 16, policySpan.length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

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

No comments: