简体   繁体   English

如何在所有屏幕上显示布局?

[英]How to show layout over all screens?

In some cases my app should show block screen. 在某些情况下,我的应用应显示屏幕截图。 This screen pop up over alll screens, cover all UI elements and doesn't react on presses on back and home button, but should have ability to input password into. 此屏幕弹出alll屏幕,覆盖所有UI元素,并且不会对按下后退和主页按钮做出反应,但应该能够输入密码。

Could you please suggest me a way how I can do that? 你能告诉我一个如何做到这一点的方法吗?

You really shouldn't even try that. 你真的不应该尝试。 The user should be in control of his own phone. 用户应该控制自己的手机。 If I want to check my email, see my notifications, swap to another app or whatever I should be able to do so whenever I can. 如果我想查看我的电子邮件,请查看我的通知,交换到另一个应用程序或我应该能够做的任何事情。

Having said that: blocking the back button can be done by overriding this method in your activity (to do nothing for example) 话虽如此:阻止后退按钮可以通过在您的活动中覆盖此方法来完成(例如,不执行任何操作)

public void onBackPressed() {
}

Create fullscreen Activity with transparent background, put your "input password info" logic, override "Home" and "BackButton" actions in that Activity . 使用透明背景创建全屏Activity ,输入“输入密码信息”逻辑, override活动中的 “主页”“后退”操作。

But this is not the best Android practice. 但这不是最好的Android练习。

I'll ignore the question of why you would want to do this, and just focus on the how. 我会忽略你为什么要这样做的问题,而只关注如何做。 If you want to display UI full screen over all other screens, you will need to use an system alert window. 如果要在所有其他屏幕上显示UI全屏,则需要使用系统警报窗口。 You will need permissions SYSTEM_ALERT_WINDOW , and set your window type to 您将需要SYSTEM_ALERT_WINDOW权限,并将您的窗口类型设置为

WindowManager.LayoutParams.TYPE_SYSTEM_ALERT

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM