軟鍵盤

方法一: 

在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;  

    }       

});

EditorInfo.IME_ACTION_DONE可以和其他的標誌一起組合使用來設置軟鍵盤,比如:
editText.setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI|EditorInfo.IME_ACTION_DONE); 
注意1EditorInfo.IME_ACTION_DONE只有對android:singleLine="true"的EditText有效。至少對HTC_A9191是這樣的。
注意2:對於EditorInfo.IME_ACTION_DONE,有些輸入法並不支持它,比如搜狐拼音輸入法。


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章