1. The setting content cannot be edited.
There are two situations in setting EditText content to be non-editable:
1. Uneditable and needs focus
android:cursorVisible="false"//不显示光标
android:editable="false"//不可编辑
android:inputType="none"//不弹出软键盘
android:textIsSelectable="false"//不可编辑状态下文字不可选
2. Not editable and does not require focus
android:focusable="false"
android:focusableInTouchMode="false"
2. Click event
-
setOnTouchListener: This method is used to listen to user touch events. When the user touches the EditText, this method will be triggered and return a boolean value indicating whether to consume the event. Normally, we can implement some custom touch event processing logic in this method, such as handling sliding, dragging, long pressing and other operations.
-
setOnClickListener: This method is used to listen to user click events. When the user clicks the EditText, this method will be triggered and the corresponding code logic will be executed. Normally, we can implement some click event processing logic in this method, such as displaying menus, popping up dialog boxes, etc.
-
setOnFocusChangeListener: This method is used to listen to focus events. When EditText gains or loses focus, this method will be triggered and the corresponding code logic will be executed. Normally, we can implement some focus event processing logic in this method, such as hiding or showing the soft keyboard, saving user input, etc.
EditText editText = (EditText)findViewById(R.id.edit);
editText.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
Log.d(TAG,"触摸了,触摸了,触摸了");
return false;
}
});
editText.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Log.d(TAG,"点击了,点击了,点击了");
}
});
editText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View view, boolean b) {
}
});