我有一个搜索区域(edittext),我想禁用退格(删除)按钮的长按操作。用户必须单击此按钮才能删除每个字符。我该怎么办?
我是新手。你能编辑评论专栏吗?短按,我想要默认动作;长期以来,我希望它能在短期内完成它的工作。
@Override
public boolean onKeyDown( int keyCode, KeyEvent event ) {
if( keyCode == KeyEvent.KEYCODE_DEL ) {
event.startTracking();
return true;
}
return super.onKeyDown( keyCode, event );
}
@Override
public boolean onKeyUp( int keyCode, KeyEvent event ) {
if( keyCode == KeyEvent.KEYCODE_DEL ) {
//Handle what you want on short press.
return true;
}
return super.onKeyUp( keyCode, event );
}
@Override
public boolean onKeyLongPress( int keyCode, KeyEvent event ) {
if( keyCode == KeyEvent.KEYCODE_DEL ) {
//Handle what you want in long press.
return true;
}
return super.onKeyLongPress( keyCode, event );
}
谢谢