天天看點

包含EditText元件的界面中,禁止自動彈出軟鍵盤

解決方法:

1)在Manifest.xml檔案中相應的activity下添加一下代碼:

android:windowSoftInputMode="stateHidden"

2)讓EditText失去焦點,使用EditText的clearFocus方法 

例如:EditText edit=(EditText)findViewById(R.id.edit); 

edit.clearFocus();

3)強制隐藏Android輸入法視窗 

例如:EditText edit=(EditText)findViewById(R.id.edit); 

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

imm.hideSoftInputFromWindow(edit.getWindowToken(),0);

4).EditText始終不彈出軟體鍵盤 

例:EditText edit=(EditText)findViewById(R.id.edit); 

edit.setInputType(InputType.TYPE_NULL);

5)在EditText标簽的外層Layout中加入focusableInTouchMode屬性

例:<LinearLayout android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:focusableInTouchMode = "true">

<EditText>...</EditText>

      </LinearLayout >