当我点击下面显示的edittext时,我在软安卓键盘上设置了一个Ok键:
<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" />
当键盘出现时,我希望用户在单击“确定”按钮时执行某些操作。但我怎么能覆盖键盘上的确定按钮来做我想做的事情
答案 0 :(得分:19)
您需要实现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 */
}
}
});