Change Actionbar title of an activity programmatically in Android Studio
In this tutorial we will change the title of Actionbar of an activity using android studio...
Step 1: Create a new project or open your project
Step 2: activity_main.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center" tools:context=".MainActivity"> <TextView android:text="Hello World!" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </LinearLayout>
Step 3: MainActivity.java
package com.blogspot.devofandroid.myapplication; import android.os.Bundle; import android.support.v7.app.ActionBar; import android.support.v7.app.AppCompatActivity; public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //set actionbar title ActionBar actionBar = getSupportActionBar(); actionBar.setTitle("New Title"); } }
Comments
Post a Comment