Let's Talk Android (Chapter 256: Toolbar Title 2 in Android)

Hello everyone, last time we talked about the example of Toolbar in Android, this time we will continue to talk about the example. Stop talking about gossip, and get back to business. Let's talk to Android together!

You guys, we introduced the method of statically modifying the Toolbar title in the last chapter. In this time, we introduced the method of dynamically modifying the Toolbar title. Here are the specific steps:

  • 1. Add Toolbar control to the page layout file, and get the control in the code;
  • 2. Set Toolbar to support Actionbar and get Actionbar (the order cannot be reversed, otherwise Actionbar will not be obtained).
  setSupportActionBar(mToolbar); 
  ActionBar actionBar = getSupportActionBar();
  • 3. Modify the title through the setTitle method of Actionbar, the code is as follows:
  actionBar.setTitle("Title");

Everyone, let’s stop here for the example of Toolbar in Android. If you want to know what other examples are, let’s listen to the next breakdown!

Guess you like

Origin blog.csdn.net/talk_8/article/details/107072329