简体   繁体   中英

what is the difference between Activity setTitle vs Toolbar setTitle

I want to set the title of my current activity to the title of image albums. I was setting the title using the Toolbar.setTitle() option. Though, I recently came across setTitle() which sets the activity name and also changes the title.

Is there any difference between using one of those or the other?

Thank you.

There are differences between them.

  • Activity 's setTitle() will set the title of window (can be retrieved using getWindow() and it's instance is used as top-level view of any Activity ) of the Activity layout.
  • getActionBar.setTitle() will set the title of DecorToolbar that is internally used to inflate the ActionBar of the Activity .(Since, it uses a kind of Toolbar so it has a companion getActionBar.setSubtitle() method).
  • Toolbar 's setTitle() will set the title of the Toolbar which can be inflated replacing the current ActionBar of the Activity using setSupportActionBar(toolbar) or can be inflated in multiple numbers in same layout file as discussed here .

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