-1

I have a textview with autoLinks set to all. I want to skip numbers like "2018" which are years, these numbers should not be highlighted. Is there a delimiter I can use in the text so that it skips those numbers while parsing?

Edit: This issue happens only in Mi devices.

rohiththammaiah
  • 153
  • 1
  • 5

4 Answers4

0

try this....

String s1="jan 2018,Saturday";  
String replaceString=s1.replace("2018","");//replaces all occurrences of "2018" to ""  
System.out.println(replaceString);

Output := jan ,Saturday.

sushildlh
  • 8,986
  • 4
  • 33
  • 77
  • I have revised the question, this is not what i was looking for. I don't want to skip the text, i just want it not to highlight the text – rohiththammaiah Nov 20 '18 at 05:17
0

Try This Code :

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    textView = findViewById(R.id.textView);
    highlightTv();

}
protected void highlightTv(){
    // Specify the text/word to highlight inside TextView
    String textToHighlight = "2018";

    // Construct the formatted text
    String replacedWith = "<font color='green'>" + textToHighlight + "</font>";

    // Get the text from TextView
    String originalString = textView.getText().toString();

    // Replace the specified text/word with formatted text/word
    String modifiedString = originalString.replaceAll(textToHighlight,replacedWith);

    // Update the TextView text
    mTextView.setText(Html.fromHtml(modifiedString));
}
Sniffer
  • 1,495
  • 2
  • 14
  • 30
  • I have revised the question, this is not what i was looking for. I don't want to skip the text, i just want it not to highlight the text – rohiththammaiah Nov 20 '18 at 05:13
  • @rohiththammaiah I updated my answer, I still didn't understand what you try to explain, if possible add your expected ScreenShot – Sniffer Nov 20 '18 at 05:24
0

Use Spanable String in this case to highlight Specific String.

Here is an example: SpannableString spannableStr = new SpannableString(originalText); ForegroundColorSpan foregroundColorSpan = new ForegroundColorSpan(Color.RED); spannableStr.setSpan(foregroundColorSpan, 15, 30, Spanned.SPAN_INCLUSIVE_EXCLUSIVE); spannableTextView.setText(spannableStr);

Set color and starting string index and ending index.

For more detail check this link click this link

0

I searched for your answer try this

private void stripUnderlines(TextView textView) {
    Spannable s = new SpannableString(textView.getText());
    URLSpan[] spans = s.getSpans(0, s.length(), URLSpan.class);
    for (URLSpan span: spans) {
        int start = s.getSpanStart(span);
        int end = s.getSpanEnd(span);
        s.removeSpan(span);
        span = new URLSpanNoUnderline(span.getURL());
        s.setSpan(span, start, end, 0);
    }
    textView.setText(s);
}

This requires a customized version of URLSpan which doesn't enable the TextPaint's "underline" property:

private class URLSpanNoUnderline extends URLSpan {
    public URLSpanNoUnderline(String url) {
        super(url);
    }
    @Override public void updateDrawState(TextPaint ds) {
        super.updateDrawState(ds);
        ds.setUnderlineText(false);
    }
}  

here is the link

Kevin Kurien
  • 812
  • 6
  • 14