xml代码:
<EditText android:id="@+id/myEdit" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:layout_marginTop="122dp" android:ems="10" android:inputType="text"
//这里是设置软件盘Enter键显示的图标,仅是图标而已 android:imeOptions="actionSearch"/>
java代码:
myEdit=(EditText)findViewById(R.id.myEdit); myEdit.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
//判断是否点了软键盘中的enter键 if(actionId==EditorInfo.IME_ACTION_SEARCH){ Toast.makeText(MainActivity.this, "你点了--->>>search", 2).show(); } return false; } });