[英]How to change the status bar color when scrolling
I'm making an app for studies using the chucknorris api我正在使用chucknorris api 为研究制作应用程序
I want that when the screen scrolls down, the status bar is transparent to match the text我希望当屏幕向下滚动时,状态栏是透明的以匹配文本
Step 1: Add a listener to scrollview第 1 步:向滚动视图添加侦听器
scrollView = (ScrollView) findViewById(R.id.scrollView);
scrollView.getViewTreeObserver()
.addOnScrollChangedListener(new
ViewTreeObserver.OnScrollChangedListener() {
@Override
public void onScrollChanged() {
if (!scrollView.canScrollVertically(1)) {
// bottom of scroll view,
//you can change status bar color here
}
if (!scrollView.canScrollVertically(-1)) {
// top of scroll view
}
}
});
Step 2: change the status bar color inside scrollview listener with the following code第 2 步:使用以下代码更改滚动视图侦听器内的状态栏颜色
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Window window = getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.setStatusBarColor(Color.BLUE);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.