我正在尝试在PhoneGap上检测showKeyboard
和hidekeyboard
事件。为此,在deviceready
事件上,我放置了以下代码:
bindEvents: function() {
document.addEventListener('deviceready', this.onDeviceReady, false);
},
// deviceready Event Handler
//
// The scope of 'this' is the event. In order to call the 'receivedEvent'
// function, we must explicity call 'app.receivedEvent(...);'
onDeviceReady: function() {
document.addEventListener("menubutton",app.onMenuKeyPress,false);
document.addEventListener("backbutton",navigateBack,false);
document.addEventListener("hidekeyboard", onKeyboardHide, false);
document.addEventListener("showkeyboard", onKeyboardShow, false);
},
这里触发并正常工作的是backbutton
事件,但hidekeyboard
和showkeyboard
事件从未被触发。
此外,为了检测它,我尝试使用window.onresize
事件,在浏览器中可以工作。以下是其代码:
window.onresize = function(){
var screenHeight = $(window).height();
alert(screenHeight);
var diff = screenInitialHeight - screenHeight;
var newHeight = screenInitialHeight-diff;
alert(newHeight);
$('#mainpage').height(newHeight);
$('#nav_container').height(newHeight);
}
但是这段代码在显示或隐藏键盘时也没有执行。这个函数只在第一次启动应用程序时执行。我在一些地方看到,对于有些人来说这些事件是有效的,所以我认为可能是我这边有些配置文件等方面存在问题。因此,以下是androidmanifest.xml代码:
<?xml version='1.0' encoding='utf-8'?>
<manifest android:hardwareAccelerated="true" android:versionCode="1" android:versionName="1.0.0" android:windowSoftInputMode="adjustPan" package="com.phonegap.move_custom" xmlns:android="http://schemas.android.com/apk/res/android">
<supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:resizeable="true" android:smallScreens="true" android:xlargeScreens="true" />
<uses-permission android:name="android.permission.INTERNET" />
<application android:debuggable="true" android:hardwareAccelerated="true" android:icon="@drawable/icon" android:label="@string/app_name" android:largeHeap="true">
<activity android:configChanges="keyboardHidden|keyboard|screenSize|locale" android:label="@string/app_name" android:name="move_custom" android:screenOrientation="portrait" android:theme="@android:style/Theme.Black.NoTitleBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-feature android:name="android.hardware.camera" android:required="false" />
<uses-sdk android:minSdkVersion="10" android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.RECORD_VIDEO" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
</manifest>
请告诉我是否需要进行任何更改。如果这些事件在某个人的应用程序中正常工作,请分享您的应用程序,以便我可以尝试检查配置和代码,以确定为什么它不能在我的应用程序中正常工作。所有良好的尝试都将受到赞赏。似乎我已经接近了解决问题,但还是有所遗漏。因此,您能提供的任何信息可能都会有所帮助。 @Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
if (getResources().getConfiguration().orientation == 2) {
super.setIntegerProperty("splashscreen", R.drawable.splash);
}
else {
super.setIntegerProperty("splashscreen", R.drawable.splashportrait);
}
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
super.loadUrl(Config.getStartUrl(), 3000);
}
onKeyboardShow
和onKeyboardHide
函数不会在其他地方损坏你的代码吗?你能把它们添加到你的问题中吗?我刚在Android 4.3上测试了一下,完全没有问题。 - benka