Android - 状态栏阻止全屏

发布于 2024-09-06 09:49:10 字数 1341 浏览 3 评论 0原文

我的应用程序启动时可以全屏正确运行。然而,在最小化然后返回应用程序后,状态栏会弹出,并将我的视图稍微向下推。如何防止状态栏移动我的视图?

这是我的布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:myapp="http://schemas.android.com/apk/res/com.example.draw"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
    <com.example.draw.DrawView 
        android:id="@+id/draw"
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content"
        android:visibility="visible"
        android:fitsSystemWindows="false"
    />      
<com.admob.android.ads.AdView     
       android:id="@+id/ad" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content"
       myapp:backgroundColor="#000000"
       myapp:primaryTextColor="#FFFFFF"
       myapp:secondaryTextColor="#CCCCCC"
       android:layout_gravity="bottom"
/>     

这是我的活动 onCreate 的一部分:

requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
    WindowManager.LayoutParams.FLAG_FULLSCREEN);  

我在清单中也有全屏主题:

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

谢谢

My app correctly runs in full screen when it's started. However after minimizing and then returning to the app, the status bar pops up and pushes my views down a little. How can I keep the status bar from moving my views?

Here is my layout:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:myapp="http://schemas.android.com/apk/res/com.example.draw"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
    <com.example.draw.DrawView 
        android:id="@+id/draw"
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content"
        android:visibility="visible"
        android:fitsSystemWindows="false"
    />      
<com.admob.android.ads.AdView     
       android:id="@+id/ad" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content"
       myapp:backgroundColor="#000000"
       myapp:primaryTextColor="#FFFFFF"
       myapp:secondaryTextColor="#CCCCCC"
       android:layout_gravity="bottom"
/>     

Here is part of my activity's onCreate:

requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
    WindowManager.LayoutParams.FLAG_FULLSCREEN);  

I also have the fullscreen theme in the manifest:

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

Thanks

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

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

发布评论

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

评论(4

高冷爸爸 2024-09-13 09:49:10

您可以通过以下方式解决此问题:(

getWindow().setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);

在 onCreate 中执行此操作)...请注意,这将破坏软键盘 (IME) - 因为 edittext 无法再滑入键盘上方的视图中。 该标志完全阻止窗口移动......

如果您需要编辑文本来同时修复状态错误,您可以这样做

someEditText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
        public void onFocusChange(View v, boolean hasFocus) {
            if (hasFocus) {
                getWindow().clearFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
            } else {
                hideKeyboard();
                getWindow().setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
            }   
        }
    });

You can fix this issue with:

getWindow().setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);

(do that in onCreate).... note that this will break the soft keyboard (IME) - as edittext can no longer slide into view above the keyboard. That flag prevents the window from moving at all....

If you need an edit text to also work while fixing the status bug you can do

someEditText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
        public void onFocusChange(View v, boolean hasFocus) {
            if (hasFocus) {
                getWindow().clearFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
            } else {
                hideKeyboard();
                getWindow().setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
            }   
        }
    });
我不是你的备胎 2024-09-13 09:49:10

只需清单上活动的 android:theme="@android:style/Theme.NoTitleBar.Fullscreen" 属性就足够了。希望它的作品

Just android:theme="@android:style/Theme.NoTitleBar.Fullscreen" attribute on your activity on the manifest is enough. Hope its works

你的笑 2024-09-13 09:49:10

我有同样的问题。我更改了插页式广告的活动并删除了:
android:主题=“@android:style/Theme.Translucent”

I had the same issue. I changed the activity for the interstitial and deleted:
android:theme="@android:style/Theme.Translucent"

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