Android - status bar prevents full screen

2019-03-20 03:56发布

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

4条回答
Emotional °昔
2楼-- · 2019-03-20 04:12

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

查看更多
我欲成王,谁敢阻挡
4楼-- · 2019-03-20 04:24

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);
            }   
        }
    });
查看更多
Rolldiameter
5楼-- · 2019-03-20 04:32

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

查看更多
登录 后发表回答