Android:有一个不可编辑的编辑文本,但仍然有一个光标

Android:有一个不可编辑的编辑文本,但仍然有一个光标,android,android-edittext,Android,Android Edittext,我正在尝试制作一个计算器,当使用GUI输入数字时,我希望用户能够单击编辑文本来更改光标,但不能启用键盘。有这样做的方法吗?您可以使用下面的代码来实现此目的 <EditText android:id="@+id/editext1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:textCursorDrawable="@null" android:cu

我正在尝试制作一个计算器,当使用GUI输入数字时,我希望用户能够单击编辑文本来更改光标,但不能启用键盘。有这样做的方法吗?

您可以使用下面的代码来实现此目的

<EditText
   android:id="@+id/editext1"
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   android:textCursorDrawable="@null"
   android:cursorVisible="true">

</EditText>

我想你想禁用android设备的输入键盘。 在这种情况下,最好的解决方案是:在清单文件和特定活动的活动构造中

<activity android:name=".MainActivity" 

    android:windowSoftInputMode="stateHidden" />
这里是另一个例子

MyEditor.setOnTouchListener(new OnTouchListener(){
@Override
public boolean onTouch(View v, MotionEvent event) {
int inType = MyEditor.getInputType(); // backup the input type
MyEditor.setInputType(InputType.TYPE_NULL); // disable soft input
MyEditor.onTouchEvent(event); // call native handler
MyEditor.setInputType(inType); // restore input type
return true; // consume touch even
}
});

简单,改用TextView。并使其像EditText一样运行。@user3466786使用android:cursorVisible=true
editText_input_field.setOnTouchListener(otl);

private OnTouchListener otl = new OnTouchListener() {
public boolean onTouch (View v, MotionEvent event) {
        return true; // the listener has consumed the event
}
};
MyEditor.setOnTouchListener(new OnTouchListener(){
@Override
public boolean onTouch(View v, MotionEvent event) {
int inType = MyEditor.getInputType(); // backup the input type
MyEditor.setInputType(InputType.TYPE_NULL); // disable soft input
MyEditor.onTouchEvent(event); // call native handler
MyEditor.setInputType(inType); // restore input type
return true; // consume touch even
}
});