简体   繁体   中英

how to set upper small text in android TextView?

I want to add small upper text in android textView

在此处输入图片说明

how would you implement this?

two textViews both layout_below the same element and then

make the second smaller?

or is there a way in one textView to put style to one word

(can be longer or shorter in other languages)?

您可以通过以下代码来实现

((TextView)findViewById(R.id.text)).setText(Html.fromHtml("2580<sup>TH</sup>"));

Solution from Android Layout framework, would put two textViews in side a Linear layout and that is it.

Another way, is making the small text as an image. Than you can add it to text view directly.

you can do it like this:

((TextView)findViewById(R.id.text)).setText(Html.fromHtml("YourRank:250<sup>TH</sup>"));

also you can do it like this:

String str=getString(R.string.rank); //YourRank:250
String str2=getString(R.string.superScript); //TH
((TextView)findViewById(R.id.text)).setText(Html.fromHtml("+str+"<sup>"+str2+"</sup>"));

it worked like charm!

You can use SpannableStringBuilder as fallows:

String text = "YourRank:250TH";

SpannableStringBuilder spannableString = new SpannableStringBuilder(text);
spannableString.setSpan(new SuperscriptSpan(), text.length() - 1, text.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

YourTextView.setText(spannableString);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM