Collapsible Toolbar: Set how much the toolbar should be collapsed in onCreate

独自空忆成欢 提交于 2019-12-03 10:55:10
Rachit

Figured out the solution finally. Once I received the new image, I passed my Bitmap as a parameter to my expandToolbar() method. The heightDp parameter specifies the initial scrolledHeight of the View. I got the idea from https://stackoverflow.com/a/30747281/3286614, thanks to Tuấn Trần Anh

public static void expandToolbar(Bitmap bmp, int heightDp) {
    CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) appBar.getLayoutParams();
    AppBarLayout.Behavior behavior = new AppBarLayout.Behavior();
    behavior.setTopAndBottomOffset(0);
    behavior.onNestedPreScroll(rootLayout, appBar, null, 0, bmp.getHeight() - heightDp, new int[2]);
    params.setBehavior(behavior);
    DetailActivity.appBar.setLayoutParams(params);
}

Hope this helps somebody.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!