Change button above text font style in android

Select another button text style using layout xml file attribute tag.

Button is most usable widget in android app designing and development area so button text is also useful and important because it helps the use to work of button. Good looking button text attracts the app user. So here is the complete step by step tutorial for Change button above text font style in android .

android-project-download-code-button

Available inbuilt button font styles list:

  • Normal.
  • Sans.
  • Serif.
  • Monospace.

Its very easy to set above four font styles on button by using attributes in button tag.

 

How to Change button above text font style in android via xml file.

Code for MainActivity.java file.

package com.android_examples.com.buttonfontchange;
import android.app.Activity;
import android.os.Bundle;

public class MainActivity extends Activity {

 @Override
 protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);
 }
}

Code for activity_main.xml layout file.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:tools="http://schemas.android.com/tools"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:paddingBottom="@dimen/activity_vertical_margin"
 android:paddingLeft="@dimen/activity_horizontal_margin"
 android:paddingRight="@dimen/activity_horizontal_margin"
 android:paddingTop="@dimen/activity_vertical_margin"
 tools:context="com.android_examples.com.buttonfontchange.MainActivity" >

 <Button
 android:id="@+id/button1"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_alignParentTop="true"
 android:layout_centerHorizontal="true"
 android:layout_marginTop="155dp"
 android:text="Normal button font"
 android:typeface="normal" />

 <Button
 android:id="@+id/button2"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_below="@+id/button1"
 android:layout_centerHorizontal="true"
 android:text="Sans button font"
 android:typeface="sans" />

 <Button
 android:id="@+id/button3"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_below="@+id/button2"
 android:layout_centerHorizontal="true"
 android:text="Serif button font"
 android:typeface="serif" />

 <Button
 android:id="@+id/button4"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_below="@+id/button3"
 android:layout_centerHorizontal="true"
 android:text="Monospace button font"
 android:typeface="monospace" />

</RelativeLayout>

Screenshot:

Change button above text font style in android

Click Here To Download Change button above text font style in android project.

Leave a Reply

Your email address will not be published. Required fields are marked *