Reputation: 839
In my android app i need to set two different sizes in single textview. i tried Spannable but not working correctly. what i tried was
String Amount = "Rs.109";
Spannable Passspan = new SpannableString(Amount);
Passspan.setSpan(new RelativeSizeSpan(0.75f), 1, 3, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
txt.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 12);
txt.setText(Passspan);
I want "Rs." as text size of 10 and rest of them as text size of 15. The total count of amount may vary to different sizes such as "Rs.109" , "Rs.1000" like that . guide me...
Upvotes: 3
Views: 6296
Reputation: 129
You can use HTML inside a TextView:
txt.setText(Html.fromHtml(styledText)));
Upvotes: 3
Reputation: 839
Thank you very much for your support guys...This helps me to get two different font size in single textview.
String Amount="Rs.109";
txt.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 15);
Spannable span = new SpannableString(Amount);
span.setSpan(new RelativeSizeSpan(0.75f), 0, 3,
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
txt.setText(span);
Upvotes: 5
Reputation: 11776
Try the following:
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="12sp"
android:text="Rs." />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:hint="Enter money" />
You can use TextView for both as well.
Upvotes: 2
Reputation: 3791
use below code hope it might help you happy coding
String text = "<body><font size=3>Rs</font><font size=2>109</font></body>";
Spanned spanned1 = Html.fromHtml(text);
tvYourTextViewObject.setText(spanned1);
Upvotes: 1
Reputation: 3366
You can try using the Html hack, but it is not a recommended solution.
txt.setText(Html.fromHtml(String.format("<font size=\"10\">Rs.</font><font size=\"15\">%s</font>", amount)));
Where amount
is the numerical value. Just as 50, 100, 1000, ...
The recommended approach is to use two TextViews
inside a horizontal LinearLayout
.
Upvotes: 4