Android 如何隐藏键盘、向EditText添加文本和移动光标
我有一个编辑文本和一个按钮。当您按下EditText时,我不想显示键盘,当您按下按钮时,我想在EditText上键入数字1 我想要的观察并没有消失 @卡里姆·米歇尔。你可以用Android 如何隐藏键盘、向EditText添加文本和移动光标,android,android-layout,android-edittext,android-button,android-cursor,Android,Android Layout,Android Edittext,Android Button,Android Cursor,我有一个编辑文本和一个按钮。当您按下EditText时,我不想显示键盘,当您按下按钮时,我想在EditText上键入数字1 我想要的观察并没有消失 @卡里姆·米歇尔。你可以用 setCursorVisible(false); setText("1"); 对于第一种情况,隐藏键盘 ETOBJ.setOnTouchListener(new View.OnTouchListener() { public boolean onTouch
setCursorVisible(false);
setText("1");
对于第一种情况,隐藏键盘
ETOBJ.setOnTouchListener(new View.OnTouchListener()
{
public boolean onTouch(View arg0, MotionEvent arg1)
{
InputMethodManager inputManager = (InputMethodManager) context.
getSystemService(Context.INPUT_METHOD_SERVICE);
inputManager.hideSoftInputFromWindow(
this.getCurrentFocus().getWindowToken(),
InputMethodManager.HIDE_NOT_ALWAYS);
return false;
}
});
当按下按钮时,您可以使用
setCursorVisible(false);
setText("1");
请尝试以下代码:
your_edit_text.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
your_edit_text.setInputType(InputType.TYPE_NULL);
EditText.setText("1");
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
your_edit_text.setSelection(your_edit_text.getText().length()); // move cursor to end
}
您可以使用setCursorVisiblefalse;我不想显示键盘我想通过按钮控制文本