Android监听键盘右下角确定键

代码改变世界

Android监听键盘右下角确定键

 

kotlin写法

<EditText
                android:id="@+id/seachFriend"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_marginLeft="5dp"
                android:background="@null"
                android:hint="搜索好友"
                android:inputType="number"
                android:imeOptions="actionSearch"
                android:paddingRight="5dp"
                android:singleLine="true"
                android:textColorHint="#cccccc" />
       


seachFriend!!.setOnEditorActionListener(OnEditorActionListener { v, actionId, event ->
            if (actionId == EditorInfo.IME_ACTION_SEARCH) {
                seachFriend!!.setText("success")
            }
            false
        })

  java写法

seachFriend.setOnEditorActionListener(new OnEditorActionListener() {               
           @Override  
            public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { 
                if (actionId == EditorInfo.IME_ACTION_DONE) { 
                    点击后处理

                } 
                return false; 

            } 
        }); 

  

 

posted @ 2017-12-12 15:07  改变世界的老十七  阅读(339)  评论(0编辑  收藏  举报