Need to disable expand on CollapsingToolbarLayout for certain fragments

前端 未结 14 1339
萌比男神i
萌比男神i 2020-11-28 08:55

I have a AppCompatActivity that controls replacing many fragments. Here is my layout for it.

activity_main.xml



        
14条回答
  •  野性不改
    2020-11-28 09:49

    You can lock appbarlayout expansion by resetting collapsing toolbar height to toolbar height

    toolbarHeight = toolbar.getLayoutParams().height;
    
    if (expand) {
        collapsingToolbar.getLayoutParams().height = getResources().getDimensionPixelOffset(R.dimen.collapsingToolbarDefaultHeight);
        appBarLayout.setExpanded(true, true);
    } else {
        //collapse
        //** it is important you do this before resetting **
        appBarLayout.setExpanded(false, true);
        appBarLayout.postDelayed(new Runnable() {
            @Override
            public void run() {
                collapsingToolbar.getLayoutParams().height = toolbarHeight;
            }
         }, 700/* 600 is default animation time to collapse */);
    }
    

提交回复
热议问题