mglisty
mglisty

Reputation: 151

Android 4.0.3 switching Enter button with Search button on soft keyboard

I'm trying to get this working: in my XML in EditText I have:

    android:imeActionLabel="Search"
    android:imeOptions="actionSearch"

But it doesn't work. In code

    search.setImeOptions(EditorInfo.IME_ACTION_SEARCH);

Doesn't work either. Any clues?

Upvotes: 1

Views: 2990

Answers (1)

AITAALI_ABDERRAHMANE
AITAALI_ABDERRAHMANE

Reputation: 2519

try this

in your xml file

<EditText
            android:id="@+id/rechercheTextView"
            android:layout_width="174dp"
            android:layout_height="wrap_content"
            android:background="@android:color/transparent"
            android:imeOptions="actionSearch"
            android:inputType="text"
             />

in your Activity

EditText rechTxt = (EditText) findViewById(R.id.rechercheTextView);
rechTxt.setOnEditorActionListener(new OnEditorActionListener() {

    public boolean onEditorAction(TextView v, int actionId,
                        KeyEvent event) {
    if (actionId == EditorInfo.IME_ACTION_SEARCH) {

        Toast.makeText(getApplicationContext(),"search",Toast.LENGTH_LONG).show();
        return true;
                    }
                    return false;
                }
            });

Upvotes: 1

Related Questions