Textview with Different Textsize

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

enter image description here

You can split string using space and add span to the string you require.

 String s= "Hello Everyone";  
String[] each = s.split(" ");

Now apply span to the string and add the same to textview.

TextView with different textSize

Try

span.setSpan(new RelativeSizeSpan(0.8f), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

How to set two different sizes for single textview in android

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);

Multiple textsize in a single textview in android

No, it is not possible from the XML, but you can do it in JAVA.

Check out this and this.

Set different text size in Android TextView

try

String asHtml = firstLine+"<br/><small>"+secondLine+"</small>";
textView.setText(Html.fromHtml(asHtml));

or simply use Spannable (AbsoluteSizeSpan)

How to add two different font size to textview text in swift

You can do that using attributedText.

try like this

var heading = "Bills or Taxes once paid through the payment gateway shall not be refunded other then in the following circumstances:"
var content = "\n \n 1. Multiple times debiting of Consumer Card/Bank Account due to ticnical error excluding Payment Gateway charges would be refunded to the consumer with in 1 week after submitting complaint form. \n \n 2. Consumers account being debited with excess amount in single transaction due to tecnical error will be deducted in next month transaction. \n \n 3. Due to technical error, payment being charged on the consumers Card/Bank Account but the Bill is unsuccessful."

let attributedText = NSMutableAttributedString(string: heading, attributes: [NSAttributedStringKey.font: UIFont.boldSystemFont(ofSize: 20)])

attributedText.append(NSAttributedString(string: content, attributes: [NSAttributedStringKey.font: UIFont.SystemFont(ofSize: 15), NSAttributedStringKey.foregroundColor: UIColor.blue]))

refundTextview.attributedText = attributedText

Font size of TextView in Android application changes on changing font size from native settings

Actually, Settings font size affects only sizes in sp. So all You need to do - define textSize in dp instead of sp, then settings won't change text size in Your app.

Here's a link to the documentation: Dimensions

However please note that the expected behavior is that the fonts in all apps respect the user's preferences. There are many reasons a user might want to adjust the font sizes and some of them might even be medical - visually impaired users. Using dp instead of sp for text might lead to unwillingly discriminating against some of your app's users.

i.e:

android:textSize="32dp"



Related Topics



Leave a reply



Submit