在AndroidMainfest.xml中選擇哪個activity,設置windowSoftInputMode屬性爲adjustUnspecified|stateHidden
方法二:
讓EditText失去焦點,使用EditText的clearFocus方法
EditText edit=(EditText)findViewById(R.id.edit); edit.clearFocus();
方法三:
強制隱藏Android輸入法窗口
EditText edit=(EditText)findViewById(R.id.edit); InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(edit.getWindowToken(),0);
設置EditText始終不彈出軟件鍵盤
例:
EditText edit=(EditText)findViewById(R.id.edit);
edit.setInputType(InputType.TYPE_NULL);
在EditText中開啓軟鍵盤的"Done"按鈕
開啓軟鍵盤的"Done"按鈕:editText.setImeOptions(EditorInfo.IME_ACTION_DONE);
editText.setOnEditorActionListener(new EditText.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_DONE) {
InputMethodManager imm = (InputMethodManager)v.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
doSomething();
return true;
}
return false;
}
});