简体   繁体   中英

Softkeyboard event Listener in Android

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.

Why view goes up ?

here is the partial of my code.

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>

Please Help....

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM