Channa
Channa

Reputation: 3737

set title bar name of a activity

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);
    }

Upvotes: 2

Views: 17872

Answers (5)

Ricky
Ricky

Reputation: 135

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" />

Upvotes: 4

PEHLAJ
PEHLAJ

Reputation: 10126

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.

Upvotes: 0

stodgy.nerd
stodgy.nerd

Reputation: 611

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.

Upvotes: 2

LHA
LHA

Reputation: 9645

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.

Upvotes: 3

Mattia Maestrini
Mattia Maestrini

Reputation: 32780

Try this

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

or this if you use appcompat-v7

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

Upvotes: 11

Related Questions