活动未全屏显示

发布于 2025-01-07 15:33:29 字数 1058 浏览 0 评论 0原文

我在我的项目中定义了一个新的活动,但全屏时遇到一些问题。

我在清单文件中定义如下:

<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 技术交流群。

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

发布评论

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

评论(1

蓝礼 2025-01-14 15:33:29

我喜欢这个问题。我省略了在问题文本中添加的方法 - 我认为它不相关。因为我希望此活动拦截(不反应)主页按钮按下,因此我重写 onAttachedToWindow() 方法,如下所示:

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

这就是问题。有时,因此,我的活动无法全屏显示。为了解决这个问题,我不知道这是否是最好的方法,我在这段代码中添加了一个延迟,如下所示:

public void onAttachedToWindow() {
    handler.sendEmptyMessageDelayed(100,100);
    super.onAttachedToWindow();
}

和处理程序:

public boolean handleMessage(Message msg) {
    getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
}

这解决了我的问题。我希望这对某人有帮助!

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:

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

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:

public void onAttachedToWindow() {
    handler.sendEmptyMessageDelayed(100,100);
    super.onAttachedToWindow();
}

and the handler:

public boolean handleMessage(Message msg) {
    getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
}

and this solved my issue. I hope this help someone!

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