android - Android 中的软键盘事件监听器

标签 android cordova keyboard

我正在制作 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/

相关文章:

android - Android 中的 Clean Master 应用程序使通知变得垃圾

Javascript 按钮 onclick 函数未定义

javascript - 停止将字符输入到表单中

python - 在 Python 中检测 NUMLOCK/CAPSLOCK/SCRLOCK keypress/keyup

android - 设计方法 : android and web service

android - Kotlin REPL 与 Android 类 unStub!ed

java - Intent.putExtra - 如何将字符串发送到下一个 Activity ?

javascript - 使用 PhoneGap 和 jQuery 时更改 anchor 标记文本

javascript - 无法在 Cordova 点击div

javascript - 如何在javascript中移动图像