gpt4 book ai didi

Android CollapsingToolbarLayout 折叠监听器

转载 作者:IT老高 更新时间:2023-10-28 13:07:32 35 4
gpt4 key购买 nike

我将 CollapsingToolBarLayoutAppBarLayoutCoordinatorLayout 一起使用,它们完全可以正常工作。我将我的 Toolbar 设置为在向上滚动时固定,我想知道是否有办法更改工具栏的标题文本,当 CollapsingToolBarLayout 它已折叠。

总结一下,当滚动展开时,我想要两个不同的标题

提前谢谢大家

最佳答案

我分享了基于@Frodio Beggins 和@Nifhel 代码的完整实现:​​

public abstract class AppBarStateChangeListener implements AppBarLayout.OnOffsetChangedListener {

public enum State {
EXPANDED,
COLLAPSED,
IDLE
}

private State mCurrentState = State.IDLE;

@Override
public final void onOffsetChanged(AppBarLayout appBarLayout, int i) {
if (i == 0) {
if (mCurrentState != State.EXPANDED) {
onStateChanged(appBarLayout, State.EXPANDED);
}
mCurrentState = State.EXPANDED;
} else if (Math.abs(i) >= appBarLayout.getTotalScrollRange()) {
if (mCurrentState != State.COLLAPSED) {
onStateChanged(appBarLayout, State.COLLAPSED);
}
mCurrentState = State.COLLAPSED;
} else {
if (mCurrentState != State.IDLE) {
onStateChanged(appBarLayout, State.IDLE);
}
mCurrentState = State.IDLE;
}
}

public abstract void onStateChanged(AppBarLayout appBarLayout, State state);
}

然后你就可以使用它了:

appBarLayout.addOnOffsetChangedListener(new AppBarStateChangeListener() {
@Override
public void onStateChanged(AppBarLayout appBarLayout, State state) {
Log.d("STATE", state.name());
}
});

关于Android CollapsingToolbarLayout 折叠监听器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31682310/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com