问题
I have a ViewPager in my layout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<android.support.v4.view.ViewPager
android:id="@+id/container"
android:layout_width="match_parent"
android:fitsSystemWindows="true"
android:layout_height="match_parent" />
</RelativeLayout>
And I want all Fragments to be in fullscreen mode (the screen should be also under status bar). I also set in that Activity:
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE |
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
);
and tried several thinks but nothing work. In a different Activity this code works OK.
Do you know where the problem is?
Look at the screenshot. It's still below the Status bar:
回答1:
put this in style.xml
<style name="Login" parent="AppTheme">
<item name="android:windowFullscreen">true</item>
</style>
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimary</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowBackground">@color/white</item>
<item name="drawerArrowStyle">@style/DrawerArrowStyle</item>
<item name="android:textColorPrimary">@color/white</item>
<item name="colorControlNormal">@color/white</item>
</style>
and this in manifest
<activity
android:name=".ui.activities.LoginActivity"
android:theme="@style/Login"/>
回答2:
For Fullscreen of Activity use fullscreen theme from manifest for that particular activity
<activity
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
.../>
or you can also apply theme programmatically using Activity.setTheme()
If you want to include your app content as a background of statusbar, it is not possible, yes in newer versions you can customize the color of statusbar background.
回答3:
Remove android:fitsSystemWindows="true"
. That flag is used when you want to keep some components from displaying over the status and navigation bars.
来源:https://stackoverflow.com/questions/34513641/android-viewpager-fitssystemwindows-fullscreen-not-working