How to change the text on the action bar

前端 未结 18 982
春和景丽
春和景丽 2020-11-22 12:30

Currently it just displays the name of the application and I want it to display something custom and be different for each screen in my app.

For example: my home scr

18条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-22 13:19

    We can change the ActionBar title in one of two ways:

    1. In the Manifest: in the manifest file, set the label of each Activity.

      android:label="@string/TitleWhichYouWantToDisplay"
      
    2. In code: in code, call the setTitle() method with a String or the id of String as the argument.

      public class MainActivity extends Activity {
      
          @Override
          public void onCreate(Bundle savedInstanceState) {
      
              setTitle(R.string.TitleWhichYouWantToDisplay);
              // OR You can also use the line below
              // setTitle("MyTitle")
              setContentView(R.layout.activity_main);
      
          }
      }
      

提交回复
热议问题