2

I'm trying to change my applications activity menu bar title. I managed to change font as follows. Anyone help me to change the name of the title. It may be just a one line, but I can't figure it out.

int actionBarTitle = Resources.getSystem().getIdentifier("action_bar_title", "id", "android");
    TextView actionBarTitleView = (TextView) getWindow().findViewById(actionBarTitle);
    if(actionBarTitleView != null){
        actionBarTitleView.setTypeface(typeFace);
    }
Channa
  • 3,267
  • 7
  • 41
  • 67

5 Answers5

10

Try this

getActionBar().setTitle("Your title");

or this if you use appcompat-v7

getSupportActionBar().setTitle("Your title");

Mattia Maestrini
  • 32,270
  • 15
  • 87
  • 94
4

You can set the title in action-bar using AndroidManifest.xml. Just add label to the activity. Like

<activity
       android:name=".DownloadActivity"
       android:label="Your Title"
       android:theme="@style/AppTheme" />
Ricky
  • 135
  • 1
  • 8
  • Thanks! This answer sets the default value without a boilerplate code. It's good to have it set instead of just setting it [with code](https://stackoverflow.com/a/29630920/5994041) otherwise the text change will be visible in UI on slower devices or emulators. For example switch from "com.some.package" to "MyApp". – Peter Badida May 11 '19 at 15:48
3

Not sure you can do it your way or not but you can use the bellow solution:

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

    final ActionBar actionBar = getActionBar();

    // actionBar
    actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);

    // titleTextView
    TextView titleTextView = new TextView(actionBar.getThemedContext());

    titleTextView.setText("Title");
    titleTextView.setTypeface( your_typeface);

    titleTextView.setOtherProperties();

    // Add titleTextView into ActionBar
    actionBar.setCustomView(titleTextView);

}

By doing this solution, you have FULL control of your textview title.

LHA
  • 9,398
  • 8
  • 46
  • 85
2

For the activity you want to change the title bar or action bar name, go to it's java file

for example if you want to change the name of MainActivity then go to MainActivity.java and add the following code

getSupportActionBar().setTitle("name of the action bar");

below this code (it will be there by default)

setContentView(R.layout.activity_main);

in the protected void onCreate(Bundle savedInstanceState)

It worked for me. I hope it will help you too.

stodgy.nerd
  • 601
  • 4
  • 9
  • 17
0

Try calling actionbar.setTitle method.

getActionBar().setTitle(title);

OR this if you are using appcompat

getSupportActionBar().setTitle(title);

There is setTitle method in activity class as well.

PEHLAJ
  • 9,980
  • 9
  • 41
  • 53