我正在制作 android phonegap 应用程序。
我在 CordovaWebView 下设置了 editText。我想获取键盘显示/隐藏事件。
尝试计算 View 高度,但失败了。当 editText 具有焦点时,将显示键盘。但 CordovaWebView 上升, View 大小不变。所以我无法获得键盘显示事件。
为什么 View 会上升?
这是我的部分代码。
MainActivity onCreateMethod()
int layoutId = R.layout.blank;
layout = new LinearLayout(this);
setContentView(layoutId);
layout.setOrientation(LinearLayout.VERTICAL);
textedit = ((Activity) this).getLayoutInflater().inflate(R.layout.main,null);
layout.addView((View) appView.getParent());
layout.addView(textedit);
layout.getChildAt(0).setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 1));
setContentView(layout);
res/layout/blank.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
</LinearLayout>
res/layout/main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<EditText
android:id="@+id/editText1"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
</LinearLayout>
请帮忙....
最佳答案
您是否尝试过监听“showkeyboard”和“hidekeyboard”事件?每次显示/隐藏软键盘时都应触发它们。
document.addEventListener("showkeyboard", function() {
console.log("Yay the keyboard is here");
}, false);
document.addEventListener("hidekeyboard", function() {
console.log("Boo the keyboard is gone");
}, false);
关于android - Android 中的软键盘事件监听器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13163743/