我正在尝试制作一个计算器,当用GUI输入数字时,我希望用户能够点击来更改光标,但不能启用键盘。无论如何这样做?
答案 0 :(得分:0)
您可以将以下代码用于此目的,
<EditText
android:id="@+id/editext1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textCursorDrawable="@null"
android:cursorVisible="true">
</EditText>
然后,
EditText input = (EditText)findViewById(R.id.edittext1);
input.setSelection(input.getText().length());
答案 1 :(得分:0)
我想你要禁用android设备的输入键盘。 在这种情况下,最佳解决方案是:(在Manifest文件和特定活动的活动构造中)
<activity android:name=".MainActivity"
android:windowSoftInputMode="stateHidden" />
或者您可以使用它来使用onTouch事件:
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
}
});