android中点击home键退出和点击back键退出有什么不同
答案:2 悬赏:70 手机版
解决时间 2021-12-29 07:26
- 提问者网友:wodetian
- 2021-12-29 03:19
android中点击home键退出和点击back键退出有什么不同
最佳答案
- 五星知识达人网友:傲气稳了全场
- 2021-12-29 04:57
点击home键不会把activity从栈中弹出,back键会弹出栈顶的activity
全部回答
- 1楼网友:十鸦
- 2021-12-29 06:34
* android常用的物理按键及其触发事件
* keycode_power 电源键
* keycode_menu 菜单键
* keycode_back 后退键
* keycode_home home键
* keycode_camera 相机键
* keycode_search 查找键
* keycode_volume_up 音量键+
* keycode_volume_down 音量键-
* keycode_volume_mute 静音
* 方向键
* keycode_dpad_center
* keycode_dpad_up
* keycode_dpad_down
* keycode_dpad_left
* keycode_dpad_right
* 键盘键
* 数字0~9 字母a~z
* keycode_0 ~ keycode_9
* keycode_a ~ keycode_z
* 提供的回调方法有
* onkeyup()、onkeydown()、onkeylongpress()
*
* @author administrator
*
*/
public class mainactivity extends activity {
private button btnclose = null;
@override
protected void oncreate(bundle savedinstancestate) {
super.oncreate(savedinstancestate);
setcontentview(r.layout.main);
btnclose = (button) findviewbyid(r.id.btnclose);
btnclose.setonclicklistener(new closelistener());
}
class closelistener implements onclicklistener {
@override
public void onclick(view v) {
// todo auto-generated method stub
finish();
}
}
@override
public boolean onkeydown(int keycode, keyevent event) {
// todo auto-generated method stub
if (keycode == keyevent.keycode_back) {
toast.maketext(this, "后退键", toast.length_short).show();
return true;
} else if (keycode == keyevent.keycode_volume_up) {
toast.maketext(this, "声音+", toast.length_short).show();
return false;
} else if (keycode == keyevent.keycode_volume_down) {
toast.maketext(this, "声音-", toast.length_short).show();
return false;
} else if (keycode == keyevent.keycode_volume_mute) {
toast.maketext(this, "静音", toast.length_short).show();
return false;
} else if (keycode == keyevent.keycode_home) {
toast.maketext(this, "home", toast.length_short).show();
return true;
}
return super.onkeydown(keycode, event);
}
@override
public boolean ontouchevent(motionevent event) {
// todo auto-generated method stub
if (event.getaction() == motionevent.action_move) {
toast.maketext(this, "action_move", toast.length_short).show();
} else if (event.getaction() == motionevent.action_up) {
toast.maketext(this, "action_move", toast.length_short).show();
} else if (event.getaction() == motionevent.action_down) {
toast.maketext(this, "action_move", toast.length_short).show();
}
return super.ontouchevent(event);
}
}
更多的事件可以参考sdk文档的motionevent、keyevent两个类,在keyevent中如果处理了keyevent.keycode_back事件,那就不会执行默认的操作,比如收到keyevent.keycode_back事件后默认是退出,如果直接return那就不会处理退出了。
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯