Top Ad unit 728 × 90

Android How to set Button font in Android

In this article we are going to learn about how to control button font using xml.

Before starting the actual coding  I am assuming you are familiar with Android basics and know how to modify your activity. If not feel free to visit respective URL.

So let's start with actual coding.

Step 1: Add a new button.

<Button android:id ="@+id/push_button" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Button - Monospace Font" android:padding="15dp" />

Above code is going add a new button in our main layout.

Step 2: Modify typeface

<Button android:id ="@+id/push_button" android:layout_width="match_parent" android:layout_height="wrap_content"  android:text="Button - Monospace Font" android:typeface="monospace" android:textSize="50sp"
android:padding="15dp"
/>

In this we are adding two new property
1. typeface is the font which we need to use.
2. textSize It is used to control the size of font.

Run your app. Below is the output.

Similarly we created three more button. Below is the image.

Exercise for you. Create other remaining button.

Below is the font we used for remaining buttons.

In this article we are controlling font using XML. If you want to know how to control font using Java code check this article.
And finally I hope you learned something from this article. Do not forgot to share the amazing app you created after reading this article.

Android How to set Button font in Android Reviewed by Mayank Sanghvi on May 14, 2017 Rating: 5

No comments:

All Rights Reserved by Android Tutorial Fun © 2014 - 2015
Powered By Blogger, Designed by Mayank Sanghvi

Contact Form

Name

Email *

Message *

Powered by Blogger.