我有我的應用程序一個EditText字段:Kindle Fire的鍵盤按鈕
<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並確實有一個返回鍵
下面的代碼作參考休息:
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);
}
StackOverflow是用於編程的問題,而且您還沒有問過任何問題。 IME不必聲明'android:imeOptions =「actionDone」',所以雖然你可能在Fire上看到這個,但問題比這個更普遍。 – CommonsWare 2012-03-01 14:18:01
我知道。我正在尋找Kindle Fire的解決方案。我編輯了我的答案,使其更加清晰,正是我所要求的 – 2012-03-01 14:25:25
您可以嘗試向EditText添加android:inputType =「textMultiLine」和android:singleLine =「true」,但是,我發現這會導致新的Jelly Bean設備。 – 2012-09-12 13:05:19