about 9 years ago
If you want to change the enter key to search key, here is the code to get the same:-
Step 1:- In your xml file add the following EditText
- <EditText
- android:id="@+id/ed_search_key"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:gravity="left"
- android:minWidth="100dp"
- android:maxWidth="100dp"
- android:maxLines="1"
- android:inputType="text"
- android:imeOptions="actionSearch"
- android:textColor="@color/white"
- android:imeActionLabel="Search"
- android:layout_gravity="center_horizontal">
- </EditText>
<EditText android:id="@+id/ed_search_key" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="left" android:minWidth="100dp" android:maxWidth="100dp" android:maxLines="1" android:inputType="text" android:imeOptions="actionSearch" android:textColor="@color/white" android:imeActionLabel="Search" android:layout_gravity="center_horizontal"> </EditText>
Step 2:- Set OnEditorActionListener to the EditText:-
- EditText edSearch= (EditText) findViewById(R.id.ed_search_key);
- edSearch.setOnEditorActionListener(new TextView.OnEditorActionListener() {
- @Override
- public boolean onEditorAction(TextView v, int actionId, KeyEvent event)
- {
- if (actionId == EditorInfo.IME_ACTION_SEARCH)
- {
- /* Here you can add your code, what and how you want to search */
- Toast.makeText(getApplicationContext(),"Searching clicked", Toast.LENGTH_SHORT).show();
- return true;
- }
- return false;
- }
- });
EditText edSearch= (EditText) findViewById(R.id.ed_search_key); edSearch.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_ACTION_SEARCH) { /* Here you can add your code, what and how you want to search */ Toast.makeText(getApplicationContext(),"Searching clicked", Toast.LENGTH_SHORT).show(); return true; } return false; } });
0 Comment(s)