Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set edittext to show search button or enter button on keyboard?

How to set EditText to show Search button or enter button on keyboard?

like image 806
user790156 Avatar asked Jun 30 '11 02:06

user790156


People also ask

What is Search button in keyboard?

The keystroke combination for searching for text within a message was Ctrl / Command + F, Ctrl / Command + F. (That is, the same key combination used twice in a row.)

How do I show soft keyboard when EditText is focused?

android:windowSoftInputMode="stateAlwaysVisible" -> in manifest File. edittext. requestFocus(); -> in code. This will open soft keyboard on which edit-text has request focus as activity appears.

What is the function of setting autoText attribute in EditText?

android:autoText If set, specifies that this TextView has a textual input method and automatically corrects some common spelling errors.


Video Answer


3 Answers

In your layout set input method to option to Search

 <EditText 
  android:imeOptions="actionSearch"
  android:inputType="text"/>

and in java code use

editText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
    @Override
    public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
        if (actionId == EditorInfo.IME_ACTION_SEARCH) {
            performSearch();
            return true;
        }
        return false;
    }
});
like image 199
Rahul Sharma Avatar answered Oct 09 '22 08:10

Rahul Sharma


Use the code to edit EditText attribute

<EditText android:imeOptions="actionSearch" />

Then do this in your java code:

editText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
    @Override
    public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
        if (actionId == EditorInfo.IME_ACTION_SEARCH) {
            performSearch();
            return true;
        }
        return false;
    }
});
like image 111
success_anil Avatar answered Oct 09 '22 10:10

success_anil


  android:singleLine="true"
  android:imeOptions="actionSearch"
like image 18
Sujith Manjavana Avatar answered Oct 09 '22 10:10

Sujith Manjavana