Android中的软键盘事件监听器

前端之家收集整理的这篇文章主要介绍了Android中的软键盘事件监听器前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在制作 android phonegap应用程序.
我在CordovaWebView下设置了editText.我想获得键盘显示/隐藏事件.
尝试计算视图高度,但失败.当editText具有焦点时,将显示键盘.但CordovaWebView上升,视图大小不变.所以我无法获得键盘显示的事件.

为什么视图上升?

这是我的部分代码.

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

<?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中

<?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相关文章