Android 调用 onAttachedToWindow() 时可以隐藏状态栏吗?

发布于 2024-12-22 12:04:18 字数 1396 浏览 2 评论 0原文

有一种方法可以在调用 onAttachedToWindow 并且窗口类型为 keyguard 时隐藏状态栏或禁用它? 我在我的活动类上尝试过这个:

这是 onCreate

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setWindowAnimations(0);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.activity_lock); 
}

public void onAttachedToWindow() {
    super.onAttachedToWindow();
    getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
}

,这个在我的清单中

android:theme="@android:style/Theme.NoTitleBar.Fullscreen";

但有时状态栏会消失,有时会出现。

如果我尝试这样做:

public void onAttachedToWindow() {
    super.onAttachedToWindow();
    getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
}

它给了我错误:

12-22 11:03:51.209: E/AndroidRuntime(9088): android.util.AndroidRuntimeException: requestFeature() must be called before adding content

There is a way to hide the status bar or disable it when the onAttachedToWindow is called and window type is keyguard ??
I have tried this on my activity class:

and this is onCreate

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setWindowAnimations(0);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.activity_lock); 
}

public void onAttachedToWindow() {
    super.onAttachedToWindow();
    getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
}

and this in my manifest

android:theme="@android:style/Theme.NoTitleBar.Fullscreen";

but sometimes the status bar disappears, and other times it appears.

If i try this:

public void onAttachedToWindow() {
    super.onAttachedToWindow();
    getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
}

it gives me the error:

12-22 11:03:51.209: E/AndroidRuntime(9088): android.util.AndroidRuntimeException: requestFeature() must be called before adding content

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

凉风有信 2024-12-29 12:04:18

好的,在以编程方式隐藏状态栏之前,您必须请求该功能:

requestWindowFeature(Window.FEATURE_NO_TITLE);

然后要请求全屏,您可以使用:

getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);

Ok, before you can hide the status bar programmatically you have to request the feature:

requestWindowFeature(Window.FEATURE_NO_TITLE);

And then to request the fullscreen you can just use:

getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文