在日常开发中,很多时候遥控一个按键要做多个功能,这时候我们可以把长按和短按用上了,定制一个按键功能首先要先定制keycode,之前我有个博文就已经写清楚了步骤,现在就不重复了,需要的去找下,接下来我直接上代码,代码如下:
else if (keyCode == KeyEvent.KEYCODE_LY_CODE ) {
Log.v(TAG, "it's KEYCODE_KEILY_KTV key and down = " + down);
try {
if (down && (repeatCount > 0) && ((event.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0)) {
mKeyIsLongPress = true;
Log.v("liu>>>", "long press >>>>>>>>>>>>>>>>>>>>>>" );
} else if (!down) {
if(!mKeyIsLongPress){
Log.v("liu>>>", "not long press >>>>>>>>>>>>>>>>>>");
} else {
mKeyIsLongPress = false;
}
}
} catch (Exception e) {
e.printStackTrace();
}
return 0;
}