I have a textView
inside with a number (variable) and a string
, how can I give the number one size larger than the string
?
the code:
TextView size = (TextView)convertView.findViewById(R.id.privarea_list_size);
if (ls.numProducts != null) {
size.setText(ls.numProducts + " " + mContext.getString(R.string.products));
}
I want ls.numproducts has a size different from the rest of the text. How to do?
Use a
Spannable String
Snap shot
You can split string using space and add span to the string you require.
Now apply
span
to thestring
and add the same totextview
.Just in case you're wondering how you can set multiple different sizes in the same textview, but using an absolute size and not a relative one, you can achieve that using
AbsoluteSizeSpan
instead of aRelativeSizeSpan
.Just get the dimension in pixels of the desired text size
and then create a new
AbsoluteSpan
based on the textYou can get this done using html string and setting the html to Textview using
txtView.setText(Html.fromHtml("Your html string here"));
For example :
---------------- Result ---------------
Result :
12345.24
Method 1
using
Method 2
using
Try spannableStringbuilder. Using this we can create string with multiple font sizes.