我刚刚在我的webview中实现了ScrollChangeListener,当用户滚动webview时。工具栏应该隐藏,这就是我做的(或者我从互联网上获得但是它有效)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
mEulaContent.setOnScrollChangeListener(new View.OnScrollChangeListener() {
@Override
public void onScrollChange(View v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
((AppCompatActivity)getActivity()).getSupportActionBar().hide();
}
});
}
然后我想,当用户向上滚动webview时,它应该显示工具栏 像
((AppCompatActivity)getActivity()).getSupportActionBar().show();
请帮帮我
答案 0 :(得分:0)
我得到了答案
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
mEulaContent.setOnScrollChangeListener(new View.OnScrollChangeListener() {
@Override
public void onScrollChange(View v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
// ((AppCompatActivity)getActivity()).getSupportActionBar().hide();
if (scrollY > oldScrollY) {
((AppCompatActivity)getActivity()).getSupportActionBar().hide();
}
if (scrollY < oldScrollY) {
((AppCompatActivity)getActivity()).getSupportActionBar().show();
// Log.i(TAG, "Scroll UP");
}
if (scrollY == 0) {
((AppCompatActivity)getActivity()).getSupportActionBar().show();
}
}
});
}