我的应用中
<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
时出现的键盘没有“完成”按钮,只有一个隐藏软键盘的按钮。
![enter image description here](https://istack.dev59.com/Hmrg2.webp)
EditText
的OnEditorActionListener
,所以除了在我的实际布局中拥有自己的“完成”按钮以将焦点从EditText中移开、隐藏键盘并使任何由更改而导致的更改生效之外,我还有点困惑该怎么办。有没有办法截取“隐藏键盘”按钮,或者有其他解决方法?
顺便说一下,我的应用程序中其他地方有一个普通的EditText视图,它没有imeOptions,也没有指定inputType,并且具有返回键。
以下是参考代码的其余部分:
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);
}
android:imeOptions =“actionDone”
,因此尽管您可能在Fire上看到这个问题,但问题比那更普遍。 - CommonsWare