Change ActionBar inside title text in android programmatically

How to set custom user written text as action bar title in android application activity.

In this tutorial we are simply modifying the action bar title text itself with the use of actionbar.setTitle() method. This method is personally designed to make changes on action bar title. So here is the complete step by step tutorial for Change ActionBar inside title text in android programmatically.

android-project-download-code-button
Note: If you are facing any type of NullPointerException error then ready my this post to solve this error.

How to Change ActionBar inside title text in android programmatically.

Code for MainActivity.java file.

 package com.changeactionbarinsidetitletext_android_examples.com;

import android.app.ActionBar;
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);
 
 ActionBar actionbar = getActionBar();
 
 actionbar.setTitle("CUSTOM ACTION BAR TEXT");
 
 }
}

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.changeactionbarinsidetitletext_android_examples.com.MainActivity" >

 
</RelativeLayout>

Screenshot:

Change ActionBar inside title text in android programmatically

Click here to download Change ActionBar inside title text in android programmatically project with source code.

Leave a Reply

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