1,首先在布局中添加 android:imeOptions="actionSearch
2,然後java代碼中設定代碼:
et_input_password.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId,
KeyEvent event) {
if ((actionId == 0 || actionId == 3) && event != null) {
LogUtil.E(et_input_password.getText().toString().trim());//寫你要做的事情
return true;
}
return false;
}
});