android 软键盘回车变搜索

android 软键盘回车变搜索_第1张图片


两种方法:

1.xml

android:imeOptions="actionSearch"


<EditText
        android:id="@+id/et_search"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:ems="10"
        android:imeOptions="actionSearch"
        android:inputType="text" >

        <requestFocus />
    </EditText>



2.代码控制

et_search.setImeOptions(EditorInfo.IME_ACTION_SEARCH);


完整代码

EditText et_search = (EditText) findViewById(R.id.et_search);
		et_search.setImeOptions(EditorInfo.IME_ACTION_SEARCH);
		et_search.setOnEditorActionListener(new OnEditorActionListener() {

			@Override
			public boolean onEditorAction(TextView arg0, int keyCode,
					KeyEvent arg2) {
				if (keyCode == EditorInfo.IME_ACTION_SEARCH) {
					// 先隐藏键盘
					((InputMethodManager) getSystemService(INPUT_METHOD_SERVICE))
							.hideSoftInputFromWindow(MainActivity.this
									.getCurrentFocus().getWindowToken(),
									InputMethodManager.HIDE_NOT_ALWAYS);
					Toast.makeText(MainActivity.this, "YQY_Editor",
							Toast.LENGTH_SHORT).show();
				}
				return false;
			}
		});




android:imeOptions="actionSearch"

你可能感兴趣的:(android,搜索,软键盘)