按下“菜单按钮”将调用我的ActionBar。它工作正常
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if(keyCode == KeyEvent.KEYCODE_MENU){
if (mActionBar.isShowing()) {
mActionBar.hide();
}
else {
mActionBar.show();
}
}else if(keyCode == KeyEvent.KEYCODE_BACK){
WebView myWebView = (WebView)findViewById(R.id.webView1);
myWebView.goBack();
}
return true;
}
当用户在显示ActionBar时触摸屏幕时,ActionBar应该消失 但它不会检测onTouch事件。为什么呢?
public boolean onTouch(View view, MotionEvent event) {
switch(event.getAction() & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_DOWN:
if (mActionBar.isShowing()) {
mActionBar.hide();
}
case MotionEvent.ACTION_UP:
break;
case MotionEvent.ACTION_POINTER_UP:
break;
}
return true;
}
更新:
View.OnTouchListener mDelayHideTouchListener = new View.OnTouchListener(){
public boolean onTouch(View view, MotionEvent event) {
switch(event.getAction() & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_DOWN:
if (mActionBar.isShowing()) {
mActionBar.hide();
}
case MotionEvent.ACTION_UP:
break;
case MotionEvent.ACTION_POINTER_UP:
break;
}
return true;
}
};
它仍然不起作用:(
答案 0 :(得分:0)
将返回值更改为false
return false;