简体   繁体   中英

Should toolbar's title change according to activity?

So, really silly question but should toolbar title change from activity to activity? I searched for it on the Material Design Guidelines but couldn't find it. As of now it just display the app's name on the toolbar on all activities. I am wondering if it follows material design guidelines/best practices on Android to keep it or change it according to the activity being presented.

So, should it be like the same on all activities or is it advisable/recommended to change it like: Going from home screen to Chats activity it would be App_name -> Chats instead of App_name -> App_name?

If so, what is the best way to change the title according to each activity?

Should toolbar's title change according to activity?

That depends on you not Material Design. Do you want to tell users clearly that this is another part of your app? Do you want to promote brand? Does this activity need a title at all?

what is the best way to change the title according to each activity?

I'll assume this is a technical question.

You have to mind two usages:

  1. The activity title (or label ) that's advertised to the operating system. This is used in launcher icons and in Recent Apps screen. It's also the default title text shown in the app (if applicable, read further).
  2. The title text shown in the app.

How to assign activity title

Case 1) You have title in the manifest

If you defined the activity title in the manifest like so

<activity android:label="Some title"/>

if you don't specify it it inherits the app name.

Case 2) Assign title at run time

You can set the activity title manually at run time like so

activity.setTitle("Some title");
activity.setTitle(R.string.some_title);

Note: Inside an activity it's just setTitle(...) .

Show title on screen

The default title will get automatically shown in Action Bar when you

setSupportActionBar(toolbar)

or if you manage a Toolbar yourself, you can set the title manually

toolbar.setTitle(activity.getTitle());

If you change the activity title later you'll also have to repeat the call on toolbar, there's nothing automatic about the process. I'm not sure about the Action Bar case.

You can also set the Toolbar title to anything else you like

toolbar.setTitle("Some title");
toolbar.setTitle(R.string.some_title);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM