安卓EditText 设置不可编辑 但可垂直滑动
时间: 2024-01-06 19:07:15 浏览: 35
要实现此功能,可以通过设置 EditText 的属性来实现。
1. 在布局文件中,将 EditText 的属性设置为不可编辑:
```
<EditText
android:id="@+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:editable="false" />
```
2. 在代码中,设置 EditText 的可垂直滑动属性:
```
EditText editText = findViewById(R.id.editText);
editText.setVerticalScrollBarEnabled(true);
editText.setMovementMethod(new ScrollingMovementMethod());
```
这样就可以实现 EditText 不可编辑但可垂直滑动的效果了。
相关问题
安卓EditText 不可编辑 可垂直滑动
要实现安卓的EditText不可编辑但可垂直滑动,可以使用以下代码:
```
EditText editText = findViewById(R.id.edit_text);
editText.setEnabled(false);
editText.setKeyListener(null);
editText.setVerticalScrollBarEnabled(true);
editText.setMovementMethod(new ScrollingMovementMethod());
```
其中,`setEnabled(false)`表示不可编辑,`setKeyListener(null)`表示没有键盘输入,`setVerticalScrollBarEnabled(true)`表示显示垂直滚动条,`setMovementMethod(new ScrollingMovementMethod())`表示可滑动。注意,如果没有设置`setMovementMethod`,则无法滑动。
android EditText设置不可编辑
Android EditText不可编辑,可以通过以下两种方式实现:
1.设置EditText的属性为android:editable="false"或android:inputType="none",这样就可以禁止用户对EditText进行编辑。
2.在Java代码中通过setFocusable(false)和setFocusableInTouchMode(false)方法来禁止EditText获取焦点,从而实现不可编辑的效果。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)