Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Controlling Ok SoftKeyboard buttons Android

I set an Ok key on soft android keyboard when i click on the edittext shown below:

 <EditText
            android:id="@+id/rlMP3SeekContainer"
            android:layout_width="0dp"
            android:layout_height="40dp"
            android:layout_weight="1"
            android:background="@drawable/text_rougea"
            android:singleLine="true" 
            android:imeOptions="actionDone"
            android:ems="10"
            android:hint="@string/hint_deezer_search"
            android:paddingLeft="@dimen/eight_dp"
            android:paddingRight="@dimen/eight_dp"
            android:textColor="@color/black"
            android:textColorHint="@color/gray_text"
            android:textSize="@dimen/twelve_sp" />

When the keyboard appear i want the user when clicking on the ok button do something. but how can i override the ok button on the keyboard to do whatever i want

like image 674
Dimitri Avatar asked Jul 04 '13 11:07

Dimitri


People also ask

How do I change the Done button on my Android phone keyboard?

First you need to set the android:imeOptions attribute equal to actionDone for your target EditText as seen below. That will change your 'RETURN' button in your EditText's soft keyboard to a 'DONE' button. Save this answer.

How do I turn off soft keyboard on Android?

You can force Android to hide the virtual keyboard using the InputMethodManager, calling hideSoftInputFromWindow , passing in the token of the window containing your focused view. This will force the keyboard to be hidden in all situations. In some cases, you will want to pass in InputMethodManager.


1 Answers

You need to implement the OnEditorActionListener:

yourEditText.setOnEditorActionListener(
        new EditText.OnEditorActionListener() {
    @Override
    public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
          if (actionId == EditorInfo.IME_ACTION_DONE) {
            /* your code here */
          }
    }
});
like image 88
Thommy Avatar answered Sep 19 '22 13:09

Thommy