我想实现
android:editable="false"
但它告诉我可编辑已弃用,您可以改为使用inputType
。
所以我不知道如何使用inputType
来实现它。
答案 0 :(得分:3)
以XML
<EditText
android:id="@+id/myEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Hint"
android:focusable="false"
android:clickable="false"
android:cursorVisible="false"
/>
使用此代码,您可以在运行时获得相同的结果
EditText et = findViewById(R.id.myEditText);
et.setFocusable(false);
et.setClickable(false);
et.setCursorVisible(false);
答案 1 :(得分:2)
以上所有建议XML标记更改的答案似乎都不起作用。但是我设法通过代码获得了类似的结果。
只需使用:
editText.setKeyListener(空);
答案 2 :(得分:1)
使用
android:inputType="none"
代替
android:editable="false"
答案 3 :(得分:0)
使用
android:clickable =“ false”
。但是如果您要使用onclick监听器。不要使用
android:clickable =“ false”
..使用
android:cursorVisible =“ false” android:focusable =“ false”。
答案 4 :(得分:0)
您可以通过TextWatcher控制EditText的行为
@Override
public void onTextChanged(String text) {
setEditTextCurrentValue((isEditTextEditable())?text:getEditTextCurrentValue());
}
因此用户可以进入控件,可以复制其内容。但如果您禁止,他将无法更改。
答案 5 :(得分:0)
如果您想使用单击编辑文本并禁用输入,请使用此选项
android:clickable="false"
android:cursorVisible="false"
android:focusable="false"
android:focusableInTouchMode="false"