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?
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.
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>