Henry
Henry

Reputation: 1042

Making first word/character of string in textview bigger

I have been searching online but haven't managed to find something that I could use. I have text in my textview that will have text something like;

1 Person
2 Person
3 Person

the text is formatted like this (1\nperson), (2\nperson) .... so adding space between the number and the person string.

What I want to do is make the number of each string bigger. For example;

enter image description here

I have searched online and the links / similar things I found are not that helpful:

Is it possible to have multiple styles inside a TextView?

TextView with different textSize

The default font size for the textview is 15, so the person string font size will always be 15, what I want to do is make the numbers bigger, for example to font size 20.

Upvotes: 1

Views: 1502

Answers (2)

Buddy
Buddy

Reputation: 11028

I think this would work:

Spannable span = new SpannableString(textView.getText());
span.setSpan(new RelativeSizeSpan(1.5f), 0, 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
textView.setText(span);

Upvotes: 4

Nouvel Travay
Nouvel Travay

Reputation: 6462

Why don't you use two TextViews inside a LinearLayout instead of one TextView? It will do what you need. You would put the first character in the first TextView and the rest of the String in the second TextView. If you need help doing that let me know.

Upvotes: 3

Related Questions