【问题标题】:Using setSupportActionBar() stops hamburger button when opening the navigation drawer打开导航抽屉时使用 setSupportActionBar() 停止汉堡按钮
【发布时间】:2016-01-22 15:28:40
【问题描述】:

我刚刚开始开发一个小型应用程序,并且想将Toolbar 标题更改为用户从导航抽屉中选择的片段的名称,但是将Toolbar 设置为操作栏能够使用:

getSupportActionBar.setTitle("[insert category here]") 

工具栏的汉堡按钮在单击时停止打开导航抽屉。 (您仍然可以通过从左侧拖入来打开它。

有谁知道如何解决这个问题和/或有谁知道更改工具栏标题的另一种方法? (我通过谷歌搜索找到了这种方法)。

【问题讨论】:

    标签: android android-actionbar navigation-drawer toolbar hamburger-menu


    【解决方案1】:

    在您的 Activity 中试试这个:

    public void setActionBarTitle(String title) {
        getSupportActionBar().setTitle(title);
    }
    

    这是给你的Fragment(你可以在OnCreateonResume方法上使用它):

    @Override
    public void onResume(){
        super.onResume();
    
        // Set the title 
        ((MainFragmentActivity) getActivity()).setActionBarTitle("Your title");
    }
    

    另外,看看:

    Change ActionBar title using Fragments

    Setting Custom ActionBar Title from Fragment

    【讨论】:

    • 谢谢 - 这是一个非常好的解决方案,效果很好
    猜你喜欢
    • 2022-08-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多