EditText 不可编辑 可滑动
时间: 2024-01-06 13:07:02 浏览: 38
如果您想让一个 EditText 不可编辑但可滑动,可以使用以下代码:
```
EditText editText = findViewById(R.id.editText);
editText.setFocusable(false);
editText.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_UP) {
v.getParent().requestDisallowInterceptTouchEvent(false);
} else {
v.getParent().requestDisallowInterceptTouchEvent(true);
}
return false;
}
});
```
这个代码会禁止 EditText 的焦点,使其不可编辑。同时,通过设置一个触摸事件的监听器,可以使得当用户滑动 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获取焦点,从而实现不可编辑的效果。
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.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)