活动未全屏显示
我在我的项目中定义了一个新的活动,但全屏时遇到一些问题。
我在清单文件中定义如下:
<activity android:name=".Test"
android:launchMode="singleInstance" android:screenOrientation="portrait"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
.............
>
如果我从另一个活动启动该活动,我会得到所需的全屏。问题是当我从 BroadcastReceiver 启动此活动时 - 我需要在 BroadcastReceiver 内打开此活动,如下所示:
public void onReceive(Context context, Intent intent) {
Intent test = new Intent(context, Test.class);
test.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(test);
}
我也尝试过这样的操作:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.test);
}
如果该活动从我的 BroadcastReciever 启动,则不会全屏。
为什么我在这种情况下无法全屏显示? Activity 创建并可见后,有什么办法可以请求全屏吗?
I defined a new Activity on my project and I have some trouble with fullScreen.
I defined in the manifest file like this:
<activity android:name=".Test"
android:launchMode="singleInstance" android:screenOrientation="portrait"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
.............
>
If I start the activity from another activity, I got the desired full screen. The problem is when I start this activity from a BroadcastReceiver - I need to open this activity inside a BroadcastReceiver something like this:
public void onReceive(Context context, Intent intent) {
Intent test = new Intent(context, Test.class);
test.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(test);
}
I tried like this too:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.test);
}
and no full screen if the activity starts from my BroadcastReciever.
Why I don't get full screen on this case? There is any way to request full screen after the Activity is created and visible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我喜欢这个问题。我省略了在问题文本中添加的方法 - 我认为它不相关。因为我希望此活动拦截(不反应)主页按钮按下,因此我重写 onAttachedToWindow() 方法,如下所示:
这就是问题。有时,因此,我的活动无法全屏显示。为了解决这个问题,我不知道这是否是最好的方法,我在这段代码中添加了一个延迟,如下所示:
和处理程序:
这解决了我的问题。我希望这对某人有帮助!
I fond the issue. There is a method I omitted to add in question text - I didn't thought it's relevant. Because I want this activity to intercept (do not react) home button press, and for this reason I override onAttachedToWindow() method like this:
And here is the issue. Some times, because of this, my activity didn't get full screen. To fix this, I don't know if this is the best way, I added a delay to this code, like this:
and the handler:
and this solved my issue. I hope this help someone!