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
    • 670
    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

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

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: