我遇到一个简单的问题,我试图在谷歌找到解决方案,但没有得到任何解决方案因为搜索关键字我认为如此。我通过javascript显示警告框,但当用户触摸空白(警报窗口外)屏幕时它会自动关闭我的意思是没有用户交互也关闭它。 它还没有关闭 Android 2.2版本。它只关闭更高版本。可能是什么问题?请问有人遇到这个问题吗?
下面的代码是小图片的触摸事件。 警告框在屏幕中心提示但是当用户在警告框窗口外触摸时会关闭
$('#bombImg').on('touchstart',function(touchEvent) {
sound = new Media("/android_asset/www/beep2.mp3");
sound.play();
document.getElementById('resetBtn').disabled = false;
document.getElementById('trns').style.display = "none";
document.getElementById('bombImg').style.display = "none";
document.getElementById('cityImg').style.position = 'absolute';
document.getElementById('bomb').style.display = "block";
enableZoomButtons();
window.alert("Bomb defused");
touchEvent.preventDefault();
});
这是我的Java代码
public class Adventure extends DroidGap {
@SuppressLint({ "SetJavaScriptEnabled", "NewApi" })
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.setIntegerProperty("splashscreen", R.drawable.logo);
// super.setIntegerProperty("splashscreen", R.drawable.splash);
//super.setStringProperty("loadingDialog", "Loading..");
super.loadUrl("file:///android_asset/www/index.html", 10000);
this.setFinishOnTouchOutside(false);
super.appView.addJavascriptInterface(new JavaScriptInterface(this,
appView, this), "MyAndroid");
appView.setOnClickListener(null);
WebSettings settings = appView.getSettings();
settings.setBuiltInZoomControls(true);
settings.setSupportZoom(true);
settings.setDefaultZoom(ZoomDensity.MEDIUM);
appView.getSettings().setUseWideViewPort(false);
appView.getSettings().setJavaScriptEnabled(true);
// appView.loadUrl("javascript:getValue()");
}
}
请有人回答此问题
答案 0 :(得分:0)
Chrome使用默认的Android对话框显示与alert,prompt,confirm方法对应的UI。
Dialog类有一个名为setCanceledOnTouchOutside的方法来管理标志。当标志为true时,点击对话框外部意味着用户取消对话框(类似于在桌面浏览器中按ESC键)。
在旧版本的Android中,默认情况下此标志为false。在较新的版本(根据此http://tofu0913.blogspot.ro/2012/09/android-dialog-setcanceledontouchoutside.html的ICS +)中,默认情况下该标志为真。
如果你想获得你想要的东西,你可能会使用叠加层和一些模拟警报的HTML。
对于想要进一步测试的人:http://jsfiddle.net/s7TWH/(我测试过2.3 - flag是假的,4.4 - flag是真的):
$('#bombImg').on('touchstart',function(touchEvent) {
window.alert("Bomb defused");
touchEvent.preventDefault();
});