Android中EditText阻止手動輸入和隱藏軟鍵盤

1.阻止手動輸入

//設置EditText可以點擊但是不可以輸入
		edCity.setCursorVisible(false);
		edCity.setFocusable(false);
		edCity.setFocusableInTouchMode(false);

2.取消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 >
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章