Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

detect keyboard search button

I change android soft keyboard to show search icon rather than Enter icon. My question is: how i can detect that user click on that search button?

like image 473
Fcoder Avatar asked Mar 30 '12 17:03

Fcoder


People also ask

What is the search button of keyboard?

The keystroke combination for searching for text within a message was Ctrl / Command + F, Ctrl / Command + F.

How do I know if my keyboard is visible?

Android provides no direct way to determine if the keyboard is open, so we have to get a little creative. The View class has a handy method called getWindowVisibleDisplayFrame from which we can retrieve a rectangle which contains the portion of the view visible to the user.

How do I dismiss my keyboard on Android?

To dismiss the keyboard, call clearFocus() on the respective element when the button is clicked.


1 Answers

In the edittext you might have used your input method options to search.

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

Now use the Editor listener on the EditText to handle the search event as shown below:

editText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
    @Override
    public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
        if (actionId == EditorInfo.IME_ACTION_SEARCH) {
           // Your piece of code on keyboard search click 
            return true;
        }
        return false;
    }
});
like image 137
Arpit Garg Avatar answered Sep 23 '22 01:09

Arpit Garg