1、需要在xml中添加: android:imeOptions="actionSearch" 2、在Java中设置EditText: inputSearch.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (event != null && event.getKeyCode() == KeyEvent.KEYCODE_ENTER) { //当点击键盘搜索键 抬起手指时执行操作(否则会执行两次) switch (event.getAction()) { case KeyEvent.ACTION_UP://你要做的事 //关闭软键盘 SystemUtil.closeSoftKeyBoard(Activity activity); return true; default: return true; } } return false; } });
Android设置并监听软键盘点击确定键进行搜索操作
最新推荐文章于 2025-02-25 13:09:01 发布