java不可编辑的文本框_如何使编辑文本不可编辑,但在JAVA中可点击
對于我來說,沒有任何一個答案能夠產生完整的解決scheme。
指導(noob友好) ,請注意在代碼中的幾個意見。
為名為EditTextDispatched.java的自定義EditText創build一個Java類
import android.content.Context; import android.util.AttributeSet; import android.view.MotionEvent; import android.widget.RelativeLayout; /** * @author Martin Pfeffer * @see https://celox.io */ public class EditTextDispatched extends android.support.v7.widget.AppCompatEditText { private static final String TAG = "DispatchingEditText"; private boolean editable = true; public EditTextDispatched(Context context) { super(context); } public EditTextDispatched(Context context, AttributeSet attrs) { super(context, attrs); } public EditTextDispatched(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); } // get the current state public boolean isEditable() { return editable; } // set your desired behaviour public void setEditable(boolean editable) { this.editable = editable; } @Override public boolean dispatchTouchEvent(MotionEvent motionEvent) { if (editable) { // default behaviour of an EditText super.dispatchTouchEvent(motionEvent); return true; } // achieve the click-behaviour of a TextView (it's cuztom) ((RelativeLayout) getParent()).onTouchEvent(motionEvent); return true; } }
在你的xml中引用EditTextDispatched (你將不得不改變pgk-name):
調用:
private void changeEditTextBehaviour(EditTextDispatched value, boolean editable) { value.setEditable(editable); value.setEnabled(editable); }
總結
以上是生活随笔為你收集整理的java不可编辑的文本框_如何使编辑文本不可编辑,但在JAVA中可点击的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 时间周期 java_周期和持续时间 /
- 下一篇: jspider java运行_Web S