Android keyboard “Go” button to “Search”

2019-03-27 13:40发布

can any one tell how to get "Search" in place of "Go" or "Done" button in android keyboard. (not magnifying glass ) .

4条回答
不美不萌又怎样
2楼-- · 2019-03-27 13:58

Try myEditText.setImeActionLabel("Search",EditorInfo.IME_ACTION_UNSPECIFIED). IME_ACTION_UNSPECIFIED allows you to put whatever text you want in the button.

查看更多
【Aperson】
3楼-- · 2019-03-27 14:06

something like this

android:imeOptions="actionSearch"

might work. in your case

there are also other options like

android:imeActionLabel="Search"

EDIT

please check this thread as well. LINK

accroding to the above link you get full text only in landscape mode.

full label is only displayed when the IME has a large amount of space for it (such as when the standard keyboard is in fullscreen mode).

so i guess you can use android:imeOptions="actionSearch" and the text Search will appear in landscape only.

查看更多
Root(大扎)
4楼-- · 2019-03-27 14:06

Add below two line in your EditText tag :

 android:inputType="text"
 android:imeOptions="actionSearch"

And Add the setOnEditorActionListener() method to editText as below:

  etSearch.setOnEditorActionListener(new TextView.OnEditorActionListener() {
            public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                if(actionId == EditorInfo.IME_ACTION_SEARCH){
                     doSearch(); //Do whatever you intend to do when user click on search button in keyboard.
                   }

                    return true;
                }
                return false;
            }
        });
查看更多
家丑人穷心不美
5楼-- · 2019-03-27 14:14

Try this:

 <EditText
    android:id="@+id/editTextSearch"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:ems="10"
    android:imeOptions="actionSearch"
    android:singleLine="true" >
 </EditText>

Add "android:singleLine" to work properly

查看更多
登录 后发表回答