1

Activity Label tag Hi There. This question might have been answered before but i couldn't find any clear directions. I am new to android and currently learning the basics.

I am trying to change the activity label tag but somehow i couldn't find a way to do so. I have created multi screen app and would like to change each screen label as per the category. My apologies if my question is not clear.

Thank you

Farrukh Hasan
  • 11
  • 1
  • 2
  • Are you using a `Toolbar` in your layout to get the actionbar, or are you letting the system provide one for you? – Ben P. Jul 26 '17 at 18:08
  • https://stackoverflow.com/questions/10138007/how-to-change-android-activity-label – Mohammad Roshani Jul 26 '17 at 18:10
  • Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a [mcve]. Use the "edit" link to improve your *question* - do not add more information via comments. Thanks! – GhostCat Jul 26 '17 at 18:25
  • 1
    Possible duplicate of [How to change title of Activity in Android?](https://stackoverflow.com/questions/2198410/how-to-change-title-of-activity-in-android) – Lennon Spirlandelli Aug 03 '17 at 01:24

5 Answers5

1

In your manifest type android :lable ="....." Under the specific activity . If you are trying to have label from any text view in layouts ,then you can think of above answers.

0

You can change the title of activities by calling setTitle():

setTitle("My Title")
Preader
  • 23
  • 6
0

Typically,

setTitle("myTitle");

should work.

In some cases, though, you may need to call

getSupportActionBar().setTitle("myTitle");

This may be necessary depending on how you designed your activity.

anomeric
  • 688
  • 5
  • 17
0

The title setting mechanism will depend on your layout structure and the kind of AppBar/Toolbar you are using.

If you are using CoordinatorLayout with a nested CollapsingToolbarLayout, the you'll have to call setTitle() on the CollapsingToolbarLayout instance.

If you are using an AppCompatActivity you can change the title by calling:

getSupportActionBar().setTitle("New Title");

If you are using a custom Toolbar element inside your layout, you'll have to set set your title on a Toolbar, then set the Toolbar as Activity's ActionBar like so:

Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.setTitle("New toolbar Title");
setSupportActionBar(toolbar);

Note: you'll have to call setSupportActionBar(toolbar); AFTER you set the title.

vrestivo
  • 11
  • 3
0

You can write it in your activity onCreate:

setTitle("Your Title");

Or do it in AndroidManifest.xml:

<activity
    android:name=".MainActivity"
    android:label="Your Title" >
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />

        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>
Lennon Spirlandelli
  • 3,131
  • 5
  • 26
  • 51