【问题标题】:how to set title in toolbar?如何在工具栏中设置标题?
【发布时间】:2017-12-15 16:00:49
【问题描述】:

似乎很简单的问题,但找不到任何答案。 如何更改工具栏标题。

工具栏是由 AppCompat Activity 创建的,不是自定义创建的。 它具有默认应用名称。我想根据活动执行的操作更改其名称。

注意:我可以使用下面的代码更改自定义工具栏的标题,所以我不是在寻找那个。

Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
toolbar.setTitle("My Title");

【问题讨论】:

    标签: android toolbar android-titlebar


    【解决方案1】:

    您可以设置默认Toolbar标题如下:

    YourActivity.this.setTitle("Your Title");
    

    对于片段

    getActivity().setTitle("Your Title");
    

    【讨论】:

      【解决方案2】:

      getSupportActionBar().setTitle("Title")

      【讨论】:

        【解决方案3】:

        根据您的需要设置ActionBar标题

        ActionBar ab = getActionBar();
        ab.setTitle("My Title");
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2015-09-26
          • 2019-08-17
          • 1970-01-01
          • 2015-01-07
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多