Chu*_*hua 3 android focus android-edittext
我有一个 EditText,我想听听用户是否按下键盘上的“完成”按钮,我还想在用户未按下软键盘上的“完成”按钮时清除 EditText,我该怎么做?
Fro*_*and 11
要检查用户按下软键盘的“完成”按钮,请使用以下代码:
edittext.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
if(i== EditorInfo.IME_ACTION_DONE){
Toast.makeText(getApplicationContext(),"Done pressed",Toast.LENGTH_SHORT).show();
}
return false;
}
});
Run Code Online (Sandbox Code Playgroud)
要在焦点更改后清除 edittext 的文本,请使用以下代码:
edittext.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View view, boolean hasFocus) {
if(!hasFocus){
edittext.setText("");
}
}
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3338 次 |
| 最近记录: |