android studio如何设置清空编辑框
时间: 2023-06-25 19:01:47 浏览: 187
你可以使用以下方式来清空编辑框:
1. 通过代码清空编辑框:
```java
EditText editText = findViewById(R.id.editText);
editText.setText("");
```
2. 通过 XML 属性设置 clearButtonEnabled 来添加清空按钮:
```xml
<EditText
android:id="@+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter text here"
android:inputType="text"
android:imeOptions="actionDone"
android:drawableEnd="@drawable/ic_clear"
android:clearButtonEnabled="true"/>
```
当 clearButtonEnabled 设置为 true 时,会在编辑框的右侧添加一个清空按钮。
3. 通过 XML 属性设置 textIsSelectable 来添加选择文本后删除选项:
```xml
<EditText
android:id="@+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter text here"
android:inputType="text"
android:imeOptions="actionDone"
android:textIsSelectable="true"/>
```
当 textIsSelectable 设置为 true 时,用户可以选择文本并使用删除键删除选中的文本。
阅读全文
相关推荐


















