2012-10-31 18 views
5

Ich mache Android PhoneAnwendung.
Ich setze editText unter dem CordovaWebView. Ich möchte ein Ereignis zum Anzeigen/Ausblenden der Tastatur erhalten.
Versuchen Sie, die Ansichtshöhe zu berechnen, aber nicht erfolgreich. Wenn editText den Fokus hat, wird die Tastatur angezeigt. Aber CordovaWebView geht nach oben, und die Größe der Ansicht ändert sich nicht. So kann ich kein Keyboard Event bekommen.

Softkeyboard Event Listener in Android

Warum die Ansicht nach oben geht?

Hier ist der Teil meines Codes.

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> 

Bitte um Hilfe ....

Antwort

3

Haben Sie versucht, für die "showkeyboard" und "hidekeyboard" Ereignisse? Sie sollten jedes Mal ausgelöst werden, wenn die Soft-Tastatur ein-/ausgeblendet wird.

document.addEventListener("showkeyboard", function() { 
    console.log("Yay the keyboard is here"); 
}, false); 
document.addEventListener("hidekeyboard", function() { 
    console.log("Boo the keyboard is gone"); 
}, false); 
+0

Danke! Ich habe versucht. In CordovaWebView flogen diese Ereignisse korrekt, aber wenn editText den Fokus verloren hat, wurde das showkeyboard Ereignis ausgelöst ... Und mit "this.getWindow(). SetSoftInputMode (LayoutParams.WRAP_CONTENT);" showkeyboard gefeuert, wenn editText gezeigt wird ... – Yajap

+0

wurde zu "this .getWindow(). setSoftInputMode (LayoutParams.WRAP_CONTENT); " zu "this.getWindow(). setSoftInputMode (WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);", Ereignis gefeuert !!!!! Vielen Dank!!! – Yajap

+0

Hallo Simon, dieses Ereignis wird nicht auf iOS-Geräten ausgelöst, gibt es auch einen Workaround dafür. –

Verwandte Themen