簡體   English   中英

如何檢測Android軟鍵盤“ Will Show”事件

[英]How to detect android soft keyboard “Will Show” event

我有一個cordova android應用程序。 我試圖防止當用戶單擊html輸入或以編程方式獲得輸入焦點時顯示本機android鍵盤。 它在那里為android之類的東西:

keyboard.addEventListener('will-show', 
   functon(event){
     event.disableKeyboardShow();
});

提前致謝!

我不知道是否有您所指出的事件。 但是您可以通過執行以下操作來防止鍵盤自動顯示:

1)在您的onCreate()上插入:

    InputMethodManager imm = (InputMethodManager) this.getSystemService(Activity.INPUT_METHOD_SERVICE);
    View view = this.getCurrentFocus();
    if (view == null) {
        view = new View(this);
    }
    imm.hideSoftInputFromWindow(view.getWindowToken(), 0);

2)然后,通過在EditText的父布局中添加android:focusable="true"android:focusableInTouchMode="true"元素,確保您的EditText可以在需要時獲得焦點,如下所示:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linearLayout" android:focusable="true" android:focusableInTouchMode="true">

如果您仍然不希望EditText成為焦點,請在步驟2的元素上添加false並插入另一個元素: android:descendantFocusability="blocksDescendants"

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM