代码改变世界
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;
}
});