我的应用程序中有一个EditText字段:
<EditText
android:id="@+id/task_buy_edit_mass_editText1"
android:minWidth="100dip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="numberDecimal"
android:imeOptions="actionDone" >
</EditText>问题是,在我的Kindle Fire上,当用户想要编辑EditText时出现的键盘没有完成按钮,只有隐藏软键盘的按钮

如果我能截取上面截图中突出显示的“隐藏键盘”按钮,那就不成问题了。然而,它似乎不会触发我附加在EditText上的OnEditorActionListener,所以除了在我的实际布局中有我自己的“完成”按钮之外,我还有点不知道该做什么,以便将焦点从EditText上移开,隐藏键盘,并根据数字的变化进行任何更改
有没有办法拦截“隐藏键盘”按钮,或者有什么替代的解决方案?
顺便说一句,我在应用程序的其他地方有一个常规的EditText视图,它没有imeOptions,也没有指定inputType,但有一个Return键
下面是代码的其余部分以供参考:
editText.setOnEditorActionListener(new OnEditorActionListener(){
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if(actionId==EditorInfo.IME_ACTION_DONE || actionId==EditorInfo.IME_ACTION_NEXT || actionId==EditorInfo.IME_NULL || event.getKeyCode()==KeyEvent.FLAG_EDITOR_ACTION || event.getKeyCode()==KeyEvent.KEYCODE_ENTER){
closeKeyboard(v, done_button);
return true;
}
return false;
}});
// set done button for keyboards without correct IME options
final EditText finalEditText = editText;
editText.setOnTouchListener(new OnTouchListener(){
@Override
public boolean onTouch(View v, MotionEvent event) {
done_button.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
closeKeyboard(finalEditText, v);
}});
done_button.setVisibility(View.VISIBLE);
return false;
}
});。
private void closeKeyboard(TextView v, View buttonv){
demand.setAmount(Double.parseDouble((v.getText().toString()))); // update the game
// close keyboard
InputMethodManager inputManager = (InputMethodManager) v.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
inputManager.hideSoftInputFromWindow(v.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
v.clearFocus();
buttonv.setVisibility(View.GONE);
}发布于 2013-10-26 04:37:20
正如@James Wald指出的那样,android:inputType="textMultiLine"和android:singleLine="true"是有效的。
编辑:执行上述操作将使其成为EditText多行。相反,android:imeOptions="actionGo"在所有设备上都能满足我的需求(AFAIK)。
https://stackoverflow.com/questions/9517267
复制相似问题