How to disable CollapsingToolbar's collapse when scroll has not content?

删除回忆录丶 提交于 2019-11-28 10:52:13

get your appbarlayout reference and set the setScrollFlags.

AppBarLayout.LayoutParams p = (AppBarLayout.LayoutParams) toolbar.getLayoutParams();
p.setScrollFlags(0);
toolbar.setLayoutParams(p);
Flatout

Try appbarParams.setScrollFlags(-1); and appBarLayout.setExpanded(true, true) to remove the elevation.

And if you have recyclerView in the fragment, try recyclerView.setNestedScrollingEnabled(false);

Need to disable expand on CollapsingToolbarLayout for certain fragments

To stop collapse of collapsingtoolbar dont give

app:layout_scrollFlags="scroll|exitUntilCollapsed" in the XML file..You can remove that code

By "scroll has no content in it", I take it that you mean "there is no fragment". For that, I think you'll have to first change the <fragment> to a <FrameLayout> , then add the fragment programatically using getFragmentManager().beginTransaction() , and then check if the fragment is present (i.e. not null) like so:

    if (getFragmentManager().findFragmentById(R.id.fragment_name) != null) { 
           // here try RKNP's code to disable the appBar from collapsing 
    }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!