簡體   English   中英

如何只隱藏軟鍵盤Android

[英]How to hide only soft keyboard android

在我的應用程序中,我正在使用選項卡活動和活動組。 在一項活動中,我有編輯文本。 當用戶單擊編輯文本時,將顯示軟鍵盤。 但是,當用戶單擊“后退”按鈕時,軟鍵盤將消失,活動堆棧上的上一個活動將出現。

在其他應用程序上,當屏幕上有軟鍵盤時,當我按下“后退”按鈕時,只有軟鍵盤關閉,除非再次按下“后退”按鈕,否則它不會返回到先前的活動。 我也希望在當前應用程序中也能做到這一點。 請幫助。

在創建方式中使用以下內容。 它工作正常。

this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

可以試試這個-**

InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
                                  imm.hideSoftInputFromWindow(v.getWindowToken(), 0);

**

 InputMethodManager imm = (InputMethodManager) 
              this.getSystemService(Context.INPUT_METHOD_SERVICE);

        if (imm.isAcceptingText()) {

            System.out.println("Software Keyboard was shown");

        } else {

             System.out.println("Software Keyboard is hidden");

             }  

這可以解決問題。 我檢查了軟鍵板是否打開,它保持在當前活動狀態,否則轉到上一個活動。

InputMethodManager imm = (InputMethodManager)getSystemService(
  Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(myEditText.getWindowToken(), 0);

檢查下面的鏈接也:-

http://developer.android.com/guide/topics/resources/runtime-changes.html#HandlingTheChange

http://developer.android.com/reference/android/view/inputmethod/InputMethodManager.html

我想這對你有幫助

protected void hideSoftKeyboard(EditText input) {
        input.setInputType(0);
        InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(input.getWindowToken(), 0);

    }

暫無
暫無

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

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