本文介绍了在Android Studio中隐藏滚动活动标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我创建了滚动活动.
我想隐藏此活动标题(Banglalink最新优惠).
I want to hide this activity title (Banglalink Latest Offers).
但是
我想在此阶段显示活动标题(Banglalink最新优惠).
I want to show activity title at this stage (Banglalink Latest Offers).
有可能吗?如果是,怎么办?
Is it possible to do?If yes, how?
推荐答案
从onCreate()
initCollapsingToolbar();
定义方法
private void initCollapsingToolbar() {
final CollapsingToolbarLayout collapsingToolbar =
(CollapsingToolbarLayout) findViewById(R.id.toolbar_layout);
collapsingToolbar.setTitle(" ");
AppBarLayout appBarLayout = (AppBarLayout) findViewById(R.id.app_bar);
appBarLayout.setExpanded(true);
// hiding & showing the title when toolbar expanded & collapsed
appBarLayout.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {
boolean isShow = false;
int scrollRange = -1;
@Override
public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
if (scrollRange == -1) {
scrollRange = appBarLayout.getTotalScrollRange();
}
if (scrollRange + verticalOffset == 0) {
collapsingToolbar.setTitle("Your app title");
isShow = true;
} else if (isShow) {
collapsingToolbar.setTitle(" ");
isShow = false;
}
}
});
}
这篇关于在Android Studio中隐藏滚动活动标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!