Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/203.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android Studio:EditText editable不推荐使用如何使用inputType_Android_Android Studio_Android Widget - Fatal编程技术网

Android Studio:EditText editable不推荐使用如何使用inputType

Android Studio:EditText editable不推荐使用如何使用inputType,android,android-studio,android-widget,Android,Android Studio,Android Widget,我想知道 android:editable="false" 但它告诉我editable已被弃用,您可以使用inputType 因此,我不知道如何通过使用inputType来实现它,如果您使用的输入类型不是文本或数字,比如日期或日期和时间,您可以使用android:inputType=“date”或android:inputType=“datetime”。如果您不使用任何此类输入类型,则可以使用android:inputType=“none” 以上所有建议XML标记更改的答案似乎都不起作用。然而

我想知道

android:editable="false"
但它告诉我editable已被弃用,您可以使用
inputType


因此,我不知道如何通过使用
inputType

来实现它,如果您使用的输入类型不是文本或数字,比如日期或日期和时间,您可以使用
android:inputType=“date”
android:inputType=“datetime”
。如果您不使用任何此类输入类型,则可以使用android:inputType=“none”

以上所有建议XML标记更改的答案似乎都不起作用。然而,我通过代码实现了类似的结果

只需使用:

editText.setKeyListener(空)

使用

android:clickable=“false”

。但如果您想使用onclick listener。不要使用

android:clickable=“false”

。。使用

android:cursorVisible=“false”android:focusable=“false”

代码 在XML中


您可以从TextWatcher控制EditText的行为

@Override
public void onTextChanged(String text) {
     setEditTextCurrentValue((isEditTextEditable())?text:getEditTextCurrentValue());
}
所以用户可以进入控件,可以复制其内容。但是如果你禁止,他就不能改变它。

使用

android:inputType="none"
而不是

android:editable="false"

如果要使用编辑文本的单击并禁用输入,请使用此选项

android:clickable="false" 
android:cursorVisible="false" 
android:focusable="false" 
android:focusableInTouchMode="false"

您应该尝试android:inputType=“none”可能与FYI重复:我在我的应用程序上发现,当
inputType=“none”
时,它仍然在字段上显示光标。无论如何,我必须设置
editable=“false”
使它消失。
android:editable="false"
android:clickable="false" 
android:cursorVisible="false" 
android:focusable="false" 
android:focusableInTouchMode="false"