1
我想在ENTER上得到一个自定义动作来工作。这里是我的EditText上Android键盘中的自定义动作按钮
<EditText
android:id="@+id/editor"
android:singleLine="true"
android:inputType="text"
android:imeActionId="@+id/submit_action"
android:imeActionLabel="Submit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:paddingTop="15dp" />
然而,当我试图抓住这一行动,我看到动作ID是5,而不是无论是在submit_action
mNameEditor.setOnEditorActionListener(new OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView arg0, int actionId, KeyEvent event) {
Toast.makeText(getActivity(), Integer.toString(actionId) ,Toast.LENGTH_LONG).show();
if (event != null && event.getAction() != KeyEvent.ACTION_DOWN) {
return false;
} else if(actionId == R.id.submit_action){
//do something
}
return true;
}
});