android软键盘的搜索按钮

作者: 墨源为水 | 来源:发表于2016-06-14 14:26 被阅读1995次

如图所示:

一.如何设置软键盘显示搜索按钮?

在XML在输入框中加入android:imeOptions="actionSearch"

二.如何监听搜索按钮?

et_key.setOnEditorActionListener(newTextView.OnEditorActionListener() {

        @Override

         public booleanonEditorAction(TextView v, intactionId,KeyEvent event) {

               if(actionId == EditorInfo.IME_ACTION_SEARCH){

               // 先隐藏键盘

               ((InputMethodManager)et_key.getContext().getSystemService(Context.INPUT_METHOD_SERVICE))

                       .hideSoftInputFromWindow(

                               SearchActivity.this

                                   .getCurrentFocus()

                                   .getWindowToken(),

                               InputMethodManager.HIDE_NOT_ALWAYS);

                   String keyWord =et_key.getText().toString().trim();

                  searchByKeyWord(keyWord);

                  return true;

            }

             return false;

       }

});

三.如何解决软键盘会把原界面挤上去的问题?

在androidMainfest.xml文件中在此Activity中写入 android:windowSoftInputMode="adjustPan"

相关文章

网友评论

    本文标题:android软键盘的搜索按钮

    本文链接:https://www.haomeiwen.com/subject/kcdudttx.html