Android: Edit Text Go Button

后端 未结 2 2017
春和景丽
春和景丽 2020-12-08 02:03

I have an Edit Text that is defined as follows.



        
相关标签:
2条回答
  • 2020-12-08 02:23

    You want a combination of android:imeOptions and setOnEditorActionListener

    <EditText android:id="@+id/some_edittext"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:imeOptions="actionSend">
    </EditText>
    
    
    some_edittext.setOnEditorActionListener(new OnEditorActionListener() {
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_SEND) {
                some_button.performClick();
                return true;
            }
            return false;
        }
    });
    

    Obviously you should change actionSend to the action you want, and update IME_ACTION_SEND correspondingly.

    0 讨论(0)
  • 2020-12-08 02:34

    Take a look at the setImeActionLabel method (or imeActionLabel and imeActionId attributes) and setOnEditorActionListener to set a listener to respond to the events.

    0 讨论(0)
提交回复
热议问题