简体   繁体   English

折叠时未设置片段标题中的CollapsingToolbarLayout

[英]CollapsingToolbarLayout in Fragment title not set when collapsed

I have a toolbar in CollapsingToolbarLayout inside AppBarLayout . 我在AppBarLayout CollapsingToolbarLayout有一个工具栏。 I set title in onResume (). 我在onResume ()中设置标题。 When I open activity and fragment, the title is shown correctly. 打开活动和片段时,标题正确显示。 But if I collapse it and press home button and open it again, it is not there anymore. 但是,如果我将其折叠并按“主页”按钮然后再次将其打开,则它不再存在。 However if I press home button when layout is expanded, the title appears as expected. 但是,如果在展开布局时按主页按钮,则标题将按预期显示。 Here is the code of setting the title: 这是设置标题的代码:

((AppCompatActivity)getActivity()).setSupportActionBar(toolbar);
    final ActionBar actionBar = ((AppCompatActivity) getActivity()).getSupportActionBar();
    if (actionBar != null) {
        actionBar.setDisplayShowTitleEnabled(true);
        actionBar.setDisplayHomeAsUpEnabled(true);
        actionBar.setTitle("TITLE HERE");
        toolbar.setTitle("TITLE HERE");
    }

What is wrong? 怎么了? Is it a bug in support library or am I doing something wrong? 是支持库中的错误,还是我做错了什么?

try setting the title of the collapsing toolbar layout. 尝试设置折叠式工具栏布局的标题。 Example: 例:

collapsingToolbarLayout = (CollapsingToolbarLayout)view.findViewById(R.id.collapsing_toolbar_layout);
collapsingToolbarLayout.setTitle("title");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM