在Android的Softkeyboard事件监听器 [英] Softkeyboard event Listener in Android
问题描述
我在做Android的PhoneGap的应用程序。
我设置EDITTEXT的CordovaWebView下。我想获得键盘显示/隐藏事件。
试计算视图的高度,但失败。当EDITTEXT具有焦点,显示键盘。但CordovaWebView上升,并查看大小不会改变。所以,我不能让键盘显示的事件。
I'm making android phonegap application.
I set editText under the CordovaWebView. I want to get keyboard show / hide event.
Try to calculate view height , but fail. When editText has focus , keyboard is shown. But CordovaWebView goes up , and view size not change. So I can't get keyboard shown event.
为什么认为上升?
下面是部分我的code。
here is the partial of my code.
MainActivity onCreateMethod()
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 /布局/ blank.xml
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 /布局/ main.xml中
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事件?他们应该在每次软键盘触发显示/隐藏。
Have you tried listening for the "showkeyboard" and "hidekeyboard" events? They should be fired every time the soft keyboard is show/hidden.
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的Softkeyboard事件监听器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!