Fla*_*h99 8 android-fragments android-recyclerview android-collapsingtoolbarlayout android-appbarlayout
我有 2 个片段(片段 A 和片段 B),它们都具有可折叠的工具栏布局和协调器布局中的相应回收站视图。
如果我在我的 recyclerview 中向上滚动(因此 CollapsingToolbarLayout 已经折叠),然后从片段 A 中打开片段 B(将 A 推到 backstack 上)。
当我通过回击返回片段 A 时。CollapsingToolbarLayout/AppBarLayout 始终展开,即使回收器视图位于相同位置。
有人经历过吗?
有一个与此相关的问题。根据克里斯·贝恩斯的说法。
在片段的onViewCreated()中添加这些行来解决问题。
ViewCompat.requestApplyInsets(mCoordinatorLayout);
Run Code Online (Sandbox Code Playgroud)
我遇到了同样的问题,所以我写了下面的代码:-
private boolean isExpand = true;
private void setTitleNotExpand(boolean isExpand) {
if(getFragmentViewHolder() != null) {
this.isExpand = isExpand;
// AppBarLayout variable
getFragmentViewHolder().appbar.setExpanded(isExpand);
}
}
Run Code Online (Sandbox Code Playgroud)
当您添加返回堆栈时,请编写以下代码:-
// write below code where you want to stick your toolbar
setTitleNotExpand(false);
// write below code where you want not to stick your toolbar
setTitleNotExpand(true);
Run Code Online (Sandbox Code Playgroud)
在你onFragmentViewHolderCreated写下下面的代码:-
getFragmentViewHolder().appbar.setExpanded(isExpand);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1394 次 |
| 最近记录: |