aj1*_*j10 73 android disabled-input android-edittext
如何EditText在Android 中的字段中禁用键入?
cha*_*nya 60
您可以使用EditText.setFocusable(false)禁用编辑EditText.setFocusableInTouchMode(true)来启用编辑;
Gab*_*gut 37
在代码中:
editText.setEnabled(false);
Run Code Online (Sandbox Code Playgroud)
或者,在XML中:
android:editable="false"
Run Code Online (Sandbox Code Playgroud)
MBy*_*ByD 12
假设editText你EditText反对:
editText.setEnabled(false);
Run Code Online (Sandbox Code Playgroud)
您可以尝试以下方法:
private void disableEditText(EditText editText) {
editText.setFocusable(false);
editText.setEnabled(false);
editText.setCursorVisible(false);
editText.setKeyListener(null);
editText.setBackgroundColor(Color.TRANSPARENT);
}
Run Code Online (Sandbox Code Playgroud)
启用EditText:

已禁用EditText:

它对我有用,希望它对你有所帮助.
只需将edittext的focusable属性设置为"false"即可.
<EditText
android:id="@+id/EditTextInput"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:focusable="false"
android:gravity="right"
android:cursorVisible="true">
</EditText>
Run Code Online (Sandbox Code Playgroud)
以下选项不起作用
在代码中:
editText.setEnabled(false);
或者,在XML中:
android:editable="false"
使能够:
private void enableEditText() {
mEditText.setFocusableInTouchMode(true);
mEditText.setFocusable(true);
mEditText.setEnabled(true);
}
Run Code Online (Sandbox Code Playgroud)
禁用:
private void disableEditText() {
mEditText.setEnabled(false);
mEditText.setFocusable(false);
mEditText.setFocusableInTouchMode(false);
}
Run Code Online (Sandbox Code Playgroud)
Edittext edittext = (EditText)findViewById(R.id.edit);
edittext.setEnabled(false);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
110982 次 |
| 最近记录: |