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:
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);
}
To change the font size of a button, use the font-size property.
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.
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.
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.
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);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With