Android 调用 onAttachedToWindow() 时可以隐藏状态栏吗?
有一种方法可以在调用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的,在以编程方式隐藏状态栏之前,您必须请求该功能:
然后要请求全屏,您可以使用:
Ok, before you can hide the status bar programmatically you have to request the feature:
And then to request the fullscreen you can just use: