3

I have an EditText field in my app:

           <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>

The problem is that on my Kindle Fire, the keyboard that appears when the user wants to edit the EditText has no Done button, just a button that hides the soft keyboard

enter image description here

That wouldn't be a problem if I could intercept the 'hide keyboard' button that I highlighted on the above screenshot. However, it doesn't seem to trigger the OnEditorActionListener I've attached to the EditText, so I'm a bit stuck what to do aside from having my own 'Done' button in my actual layout to take focus away from the EditText, hide the keyboard and make any changes that result from the number being changed

Is there a way to intercept the 'hide keyboard' button, or is there some alternative solution?

Incidentally, I have a regular EditText view elsewhere in my app that has no imeOptions nor specifies inputType and that does have a Return key

Here's the rest of the code for reference:

        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);
        }
4

1 回答 1

1

android:inputType="textMultiLine"android:singleLine="true"正如@James Wald 所指出的那样有效。

编辑:执行上述操作将使其成为 EditText 多行。而是android:imeOptions="actionGo"在所有设备(AFAIK)上为我的目的工作。

于 2013-10-25T20:37:19.897 回答