Different font size of strings in the same TextView

Use a Spannable String String s= “Hello Everyone”; SpannableString ss1= new SpannableString(s); ss1.setSpan(new RelativeSizeSpan(2f), 0,5, 0); // set size ss1.setSpan(new ForegroundColorSpan(Color.RED), 0, 5, 0);// set color TextView tv= (TextView) findViewById(R.id.textview); tv.setText(ss1); Snap shot You can split string using space and add span to the string you require. String s= “Hello Everyone”; String[] each = s.split(” … Read more

Android TextView with Clickable Links: how to capture clicks?

Based upon another answer, here’s a function setTextViewHTML() which parses the links out of a HTML string and makes them clickable, and then lets you respond to the URL. protected void makeLinkClickable(SpannableStringBuilder strBuilder, final URLSpan span) { int start = strBuilder.getSpanStart(span); int end = strBuilder.getSpanEnd(span); int flags = strBuilder.getSpanFlags(span); ClickableSpan clickable = new ClickableSpan() { … Read more

How can I change the color of a part of a TextView?

Spannable is more flexible: String text2 = text + CepVizyon.getPhoneCode() + “\n\n” + getText(R.string.currentversion) + CepVizyon.getLicenseText(); Spannable spannable = new SpannableString(text2); spannable.setSpan(new ForegroundColorSpan(Color.WHITE), text.length(), (text + CepVizyon.getPhoneCode()).length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); myTextView.setText(spannable, TextView.BufferType.SPANNABLE);

Android Paint: .measureText() vs .getTextBounds()

You can do what I did to inspect such problem: Study Android source code, Paint.java source, see both measureText and getTextBounds methods. You’d learn that measureText calls native_measureText, and getTextBounds calls nativeGetStringBounds, which are native methods implemented in C++. So you’d continue to study Paint.cpp, which implements both. native_measureText -> SkPaintGlue::measureText_CII nativeGetStringBounds -> SkPaintGlue::getStringBounds Now … Read more