Android keyboard “Go” button to “Search”

我怕爱的太早我们不能终老 提交于 2019-12-21 04:23:35

问题


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


回答1:


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




回答2:


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.




回答3:


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




回答4:


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;
            }
        });


来源:https://stackoverflow.com/questions/7156427/android-keyboard-go-button-to-search

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!