2017-04-24 92 views
-1

我在我的應用程序中使用一個編輯文本,一旦我完成輸入鍵盤想要自動隱藏而不按回按鈕。誰能幫助我....如何隱藏小鍵盤而不點擊返回按鈕

+0

爲什麼你不想在輸入完成後隱藏鍵盤? –

+0

嗨,你有沒有試過強迫它以任何方式出現?如http://stackoverflow.com/a/10420979/7813290 – Jamin

回答

1

在試試這個代碼的Edittext你會得到選項關閉鍵盤它的自我....

機器人:imeOptions = 「actionDone」

1

你應該使用TextWatcher知道當u完成打字,然後ü可以隱藏下面的鍵盤:鍵入五個字符後

EditText editText; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 

    editText = (EditText)findViewById(R.id.editText); 
    editText.addTextChangedListener(new TextWatcher() { 
     @Override 
     public void beforeTextChanged(CharSequence s, int start, int count, int after) { 

     } 

     @Override 
     public void onTextChanged(CharSequence s, int start, int before, int count) { 

      if(count == 5){ 

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

     } 

     @Override 
     public void afterTextChanged(Editable s) { 

     } 
    }); 

} 

所以在這個代碼鍵盤會自動隱藏。

試試吧。

1

調用此功能,只要輸入完整獲取

InputMethodManager imm = (InputMethodManager) getSystemService(Activity.INPUT_METHOD_SERVICE); 
//Hide: 
imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0); 

private void hideKeyboard() { 
    // Check if no view has focus: 
    View view = this.getCurrentFocus(); 
    if (view != null) { 
     InputMethodManager inputManager = (InputMethodManager) this.getSystemService(Context.INPUT_METHOD_SERVICE); 
     inputManager.hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); 
    } 
} 
1
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); 

editText.requestFocus(); 

imm.showSoftInput(editText, 0); 

試試這個(在EDITTEXT你應該把你自己的EDITTEXT)。