首先在布局文件中的EditText添加android:imeOptions="actionSearch"
<EditText
android:id="@+id/addmember_phone_ed"
android:gravity="center"
android:layout_margin="15dp"
android:padding="12dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:imeOptions="actionSearch"
android:inputType="text"/>
然后初始化添加一个事件就行
EditText phoneEd= (EditText) findViewById(R.id.addmember_phone_ed);
<pre name="code" class="java"> phoneEd.setOnEditorActionListener(new TextView.OnEditorActionListener(){
@Override
public boolean onEditorAction(TextView arg0, int arg1, KeyEvent arg2) {
// TODO Auto-generated method stub
if(arg1 == EditorInfo.IME_ACTION_SEARCH)
{
Toast.makeText(AddMemberActivity.this,"呵呵",Toast.LENGTH_SHORT).show();
// search pressed and perform your functionality.
}
return false;
}
});