我有2个编辑文本字段和一个按钮。我希望软键盘在第一个编辑文本获得焦点时显示。我想让软键盘显示“下一步”键,这样当它按下时,光标会跳到第二个编辑文本字段。
当第二个编辑文本字段获取光标时,我仍然希望软键盘显示“下一步”。现在按下“下一步”将关闭软键盘并使焦点进入按钮。
这里是我的代码:
EditText editText1 = (EditText) findViewById(R.id.some_text_field);
EditText editText2 = (EditText) findViewById(R.id.some_other_text_field);
editText1.setInputType(EditorInfo.some constant);
editText1.setFocusable(true);
editText1.setFocusableInTouchMode(true);
if (editText1.requestFocus()){
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
if (imm != null){
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED,0);
}
}
editText1.setImeOptions(EditorInfo.IME_ACTION_NEXT);
editText1.setNextFocusDownId(R.id.some_other_text_field);
editText2.setInputType(EditorInfo.some other constant);
editText2.setFocusable(true);
editText2.setFocusableInTouchMode(true);
editText2.setImeOptions(EditorInfo.IME_ACTION_DONE);
似乎非常简单。
事情是,这是第一次运行(应用程序安装后)editText1获得焦点和软键盘显示,但没有“下一步”键 - 而是显示“完成”。按“完成”将您移动到editText2(如您所愿)并将“完成”更改为“下一步。点击”下一步“现在将焦点留在editText2并关闭软键盘
如果您现在触摸editText1,显示器和“下一步”键看起来像它应该。
我能做些什么,以获得正确的行为(editText1获得焦点,“下一步”显示器)发生在该活动的第一次运行?
我以为editText1.setImeOptions(EditorInfo.IME_ACTION_NEXT);应该强制显示“下一步”键。我在想什么?