getSupportActionBar().setTitle() vs toolbar.setTitle()

前端 未结 2 1681
自闭症患者
自闭症患者 2020-12-14 08:30

I am aware that there are two methods to setting a title in an Android Activity.

Assuming I already have the following code...

2条回答
  •  旧巷少年郎
    2020-12-14 09:24

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

提交回复
热议问题