Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Different textsizes in a button

I want to create a button. This button contains a letter with a size of 22pixels and some letters to the right of it with a size of 16 pixels.

Like this:
enter image description here

How can I achieve this?

At the moment I have this:

private void setText(Button btn, String text, String underText) {
    Spannable span = new SpannableString(text + "\n" +  underText);

    btn.setText(span);
}
like image 618
Robby Smet Avatar asked Aug 30 '12 09:08

Robby Smet


People also ask

How do I change the text size inside a button?

To change the font size of a button, use the font-size property.

How do you style text inside a button?

Creating a text button The HTML <button> tag is used to create a text button. To make it a text button we need to remove its default border using border: none property. We also need to remove the default background properties using background: none . We can change the color of the text using the color property.

What is the use of font size button?

These buttons generally allow the website users to change the font size of the entire page or a certain portion of the page to a specific size to improve the readability of the page.

How do I change the font of a button in HTML?

To change font type purely with HTML, use the CSS font-family property. Set it to the value you want and place it inside a style attribute. Then add this style attribute to an HTML element, like a paragraph, heading, button, or span tag.


Video Answer


1 Answers

You can apply AbsoluteSizeSpan in your Spannable to make different size of Text in same content.

 private void setText(Button btn, String text, String underText) {

    Spannable span = new SpannableString(text + "\n" +  underText);
    span.setSpan(new AbsoluteSizeSpan(fontSize), startIndex, endIndex, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    btn.setText(span);
}
like image 98
Mohammed Azharuddin Shaikh Avatar answered Sep 19 '22 15:09

Mohammed Azharuddin Shaikh