In android app Toolbar.setTitle method has no effect – application name is shown as title
Found the solution:
Instead of:
mActionBarToolbar = (Toolbar) findViewById(R.id.toolbar_actionbar);
mActionBarToolbar.setTitle("My title");
setSupportActionBar(mActionBarToolbar);
I used:
mActionBarToolbar = (Toolbar) findViewById(R.id.toolbar_actionbar);
setSupportActionBar(mActionBarToolbar);
getSupportActionBar().setTitle("My title");
And it works.
getSupportActionBar().setTitle() vs toolbar.setTitle()
If you call setSupportActionBar(Toolbar)
,
then the Action Bar is then responsible for handling the title, therefore you need to call getSupportActionBar().setTitle("My Title");
to set a custom title.
Also check this link where toolbar.setTitle("My title");
may cause problem like below:-
In android app Toolbar.setTitle method has no effect – application name is shown as title
And toolbar is the general form of action bar.
We can have multiple toolbars as layout widget but action is not.
Thus better approach is to use getSupportActionBar().setTitle("My Title");
How to change the toolbar's title in android app?
Try to use this.setTitle(title);
in onCreate()
method.
how to set title in toolbar?
You can set default Toolbar
title as following:
YourActivity.this.setTitle("Your Title");
For fragment:
getActivity().setTitle("Your Title");
Why Application name shown by it self in app bar? And how to remove it?
to remove title from action bar try this
Toolbar toolbar=(Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setTitle("");
try this to change actionbar title
Toolbar toolbar=(Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setTitle("your title");// set your title name
Related Topics
How to Make Sticky Headers in Recyclerview? (Without External Lib)
Android Lollipop, Appcompat Actionbar Custom View Doesn't Take Up Whole Screen Width
Firebase (Fcm): Open Activity and Pass Data on Notification Click. Android
How to Programmatically Add Buttons into Layout One by One in Several Lines
Install an APK File from Command Prompt
How to Use Assert on Android Devices
How to Make an Imageview in Circular Shape
Upload Photo to Facebook with Facebook Android Sdk in Android
Connecting Mongodb from Mobile or Browser Based Application
Keyboard Showed Messed Up Elements' Position
How to Use Icons and Symbols from "Font Awesome" on Native Android Application
How to Save State During Orientation Change in Android If the State Is Made of My Classes
How to Globally Force Screen Orientation in Android
Use Uri Builder in Android or Create Url with Variables
How to Add a Library (Android-Support-V7-Appcompat) in Intellij Idea