用于向上滚动android的ScrollChangeListener

时间:2017-04-08 12:45:28

标签: android webview

我刚刚在我的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();

请帮帮我

1 个答案:

答案 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();
                 }
             }


         });

     }