Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android button font size

Tags:

android

I;ve been trying to create a custom button in android using this tutorial - http://www.gersic.com/blog.php?id=56

It works well but it doesn't say how to change the font size or weighting. Any ideas?

There was another question on here and the only answer was to use html styling but you can't change a font size in html without using css (or the deprecated font tag). There must be a better way of setting the pixel size of the font used on buttons?

like image 402
jonhobbs Avatar asked May 13 '10 00:05

jonhobbs


People also ask

How do I change the button font size?

HTML, CSS and JavaScript To change the font size of a button, use the font-size property.

How do I make the buttons bigger on my Android?

Tap the Gear icon that appears at the top of the Android keyboard. Open Preferences. Tap the Keyboard Height option. You'll see seven different options ranging from "Extra-short" to "Extra-tall." The default is "Normal." Tap the option you prefer.

How do I change font size in Kotlin?

To set Android Button font/text size, we can set android:textSize attribute for Button in layout XML file. To programmatically set or change Android Button font/text size, we can pass specified size to the method Button. setTextSize(specific_size).


2 Answers

You define these attributes in xml as you would anything else, for example:

<Button android:id="@+id/next_button"             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:text="@string/next"             android:background="@drawable/mybutton_background"             android:textSize="10sp" /> <!-- Use SP(Scale Independent Pixel) --> 

You can find the allowed attributes in the api.

Or, if you want this to apply to all buttons in your application, create a style. See the Styles and Themes development documentation.

like image 62
Cheryl Simon Avatar answered Sep 30 '22 10:09

Cheryl Simon


Button butt= new Button(_context); butt.setTextAppearance(_context, R.style.ButtonFontStyle); 

and in res/values/style.xml

<resources>        <style name="ButtonFontStyle">             <item name="android:textSize">12sp</item>     </style> </resources> 
like image 43
ashish Avatar answered Sep 30 '22 10:09

ashish