1 回答

TA贡献1064条经验 获得超383个赞
屏蔽Activity中的Home键功能,只需要在你要屏蔽的activity 中重写 onAttachToWindow() 这个函数就可以了
[java]
@Override
public void onAttachedToWindow() {
this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
super.onAttachedToWindow();
}
@Override
public void onAttachedToWindow() {
this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
super.onAttachedToWindow();
}
2.屏蔽 Dialog风格Activity的Home键功能,也需要在你要屏蔽的activity 中重写 onAttachToWindow() 这个函数,但设置window 的值需要改变为 TYPE_KEYGUARD_DIALOG
[java]
@Override
public void onAttachedToWindow() {
this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG);
super.onAttachedToWindow();
}
@Override
public void onAttachedToWindow() {
this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG);
super.onAttachedToWindow();
}
3.屏蔽AlertDialog的Home键功能
[java]
AlertDialog d = b.create();
d.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
AlertDialog d = b.create();
d.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
- 1 回答
- 1 关注
- 2698 浏览
添加回答
举报