0

Whenever I am using autoLink="all" in TextView, it is not properly autolinking the Mobile Number. It is autolinking the earlier Number(number from a text not mobile Number) as well.

Here is the layout

<TextView
    android:id="@+id/text"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Hello World!"
    android:autoLink="all"
    android:textIsSelectable="true"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

The output is attached below

Issue Image

How to avoid that issue ?

1

1 Answer 1

0

If I have understood your question clearly than you can also use ClickableSpan It also allows you to under line and clickable the fix number of characters handle the click for the same. In xml

<TextView
                android:id="@+id/textView"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="@dimen/_18sdp"
                android:layout_marginRight="@dimen/_18sdp"
                android:fontFamily="@font/lato_semibold"
                android:paddingTop="@dimen/_15sdp"
                android:textAlignment="center"
                android:textColor="@color/colorBlack"
                android:textSize="@dimen/_13sdp" />

In java class

    SpannableString ss = new SpannableString("Hello World8 123456789");
ClickableSpan clickableSpan = new ClickableSpan() {
    @Override
    public void onClick(View textView) {
        // handle on click
    }
    @Override
    public void updateDrawState(TextPaint ds) {
        super.updateDrawState(ds);

    }
};
ss.setSpan(clickableSpan, 12, 22, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

TextView textView = (TextView) findViewById(R.id.hello);
textView.setText(ss);
textView.setMovementMethod(LinkMovementMethod.getInstance());
textView.setHighlightColor(Color.TRANSPARENT);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.