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
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.
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.
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 */
}
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With