Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to change the enter key to search key in soft keyboard

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 681
    Comment on it

    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

    1. <EditText
    2. android:id="@+id/ed_search_key"
    3. android:layout_width="wrap_content"
    4. android:layout_height="wrap_content"
    5. android:gravity="left"
    6. android:minWidth="100dp"
    7. android:maxWidth="100dp"
    8. android:maxLines="1"
    9. android:inputType="text"
    10. android:imeOptions="actionSearch"
    11. android:textColor="@color/white"
    12. android:imeActionLabel="Search"
    13. android:layout_gravity="center_horizontal">
    14. </EditText>

    Step 2:- Set OnEditorActionListener to the EditText:-

    1. EditText edSearch= (EditText) findViewById(R.id.ed_search_key);
    2. edSearch.setOnEditorActionListener(new TextView.OnEditorActionListener() {
    3. @Override
    4. public boolean onEditorAction(TextView v, int actionId, KeyEvent event)
    5. {
    6. if (actionId == EditorInfo.IME_ACTION_SEARCH)
    7. {
    8. /* Here you can add your code, what and how you want to search */
    9. Toast.makeText(getApplicationContext(),"Searching clicked", Toast.LENGTH_SHORT).show();
    10. return true;
    11. }
    12. return false;
    13. }
    14. });

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Reset Password
Fill out the form below and reset your password: