How can I implement a chrome like “auto-hide navigation” for my Android app?

后端 未结 4 1723
误落风尘
误落风尘 2021-02-04 20:12

In Chrome, the address bar will be hidden/shown when user swipes up/down the content.

Can I implement the similar logic to my app?



        
4条回答
  •  花落未央
    2021-02-04 20:42

    try the following code, hope it works for you:

        private void init(){
        WebView web = new WebView(this);
        final Context context = this;
        web.setOnTouchListener(new OnTouchListener() {
    
            public boolean onTouch(View arg0, MotionEvent event) {
                // TODO Auto-generated method stub
                switch (event.getAction()) {
                case MotionEvent.ACTION_DOWN:
                    // show action bar
                    ((Activity) context).getActionBar().show();
                    break;
    
                case MotionEvent.ACTION_UP:
                    // hide action bar
                    ((Activity) context).getActionBar().hide();
                    break;
    
                default:
                    break;
                }
                return false;
            }
        });
    }
    

提交回复
热议问题