如何在用户触摸viewpager图像时隐藏操作栏和状态栏,并在用户再次触摸时显示相同内容?

时间:2016-01-23 05:53:04

标签: android android-viewpager ontouchlistener

//我尝试了下面的代码,但每次触摸时都会保持隐藏/显示调用。请建议正确的方法。

mViewPager.setOnTouchListener(new View.OnTouchListener() {




 @Override
            public boolean onTouch(View v, MotionEvent event) {
                int action = event.getAction();
                if (action == MotionEvent.ACTION_DOWN) {
                    mTouch = true;
                    Log.d("onTouch", "if, true, action down");
                    View decorView = getWindow().getDecorView();
                    // Hide the status bar.
                    int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
                    decorView.setSystemUiVisibility(uiOptions);
                    // Remember that you should never show the action bar if the
                    // status bar is hidden, so hide that too if necessary.
                    getSupportActionBar().hide();
                    mPageNoList.setVisibility(View.GONE);
                   // count++;
                }
                else if (action == MotionEvent.ACTION_MOVE) {
                    Log.d("onTouch", "else, false, action move");
                    // movement: cancel the touch press
                    mTouch = false;
                    View decorView = getWindow().getDecorView();
                    // Hide the status bar.
                    int uiOptions = View.SYSTEM_UI_FLAG_VISIBLE;
                    decorView.setSystemUiVisibility(uiOptions);
                    // Remember that you should never show the action bar if the
                    // status bar is hidden, so hide that too if necessary.
                    getSupportActionBar().show();
                    mPageNoList.setVisibility(View.VISIBLE);
                    //count++;
                }
                else if (action == MotionEvent.ACTION_UP) {
                    if (mTouch) {
                        // touch press complete, show toast
                        Log.d("onTouch", "else if, action up");
                    }
                }
                return false;
            }
        });

0 个答案:

没有答案