Android glitch opening app with full screen and list views Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of Android glitch opening app with full screen and list views without wasting too much if your time.

The question is published on by Tutorial Guruji team.

I have configured my application and activities to work on full screen mode, but I’m finding with a problem I can’t solve.

When my App starts up it goes from a loading screen to home screen, everything ok, but If I press “home” button and comeback to my App (no loading screen now, app it’s started) then the layout is displaced by the status bar, and my bottom bar is cut. This effect lasts like 0.5-1 sec.

This also happens when a heads up notifications shows up.

enter image description here

My research points to listviews or similiar views, like viewpager. It just happened on my activities with listviews, then I changed my activity to manage fragments on a view pager, tried again and now happens in every single fragment, I mean my 3rd page is a simple fragment and it didn’t happen on that one, but now with view pager it does.

I have all my activies with the same theme on manifest:

<activity
    android:name=".OpenActivity"
    android:screenOrientation="portrait"
    android:theme="@style/AppTheme.FullScreen">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>

styles.xml

<style name="AppTheme.FullScreen" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
    <item name="android:windowFullscreen">true</item>
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowActionBar">false</item>
    <item name="android:windowContentOverlay">@null</item>
    <item name="android:windowEnableSplitTouch">false</item>
</style>

main_activity.xml

<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">


<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal"
    android:background="@android:color/transparent">

    <androidx.viewpager2.widget.ViewPager2
        android:id="@+id/view_pager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingBottom="@dimen/navbar_space" />

    <fragment
        android:id="@+id/nav_bar_fragment"
        android:name="es.udc.psi1516.pickapp.navbar.NavBarFragment"
        android:layout_width="match_parent"
        android:layout_height="@dimen/navbar_height"
        android:orientation="horizontal"
        android:layout_alignParentBottom="true"  />

</RelativeLayout>

I have some code on my MainActivity.java to hide status bar:

@Override
protected void onResume() {
    super.onResume();
    hideSystemUI();
}

// This snippet hides the system bars
public void hideSystemUI() {
    int newUiOptions = getWindow().getDecorView().getSystemUiVisibility();
    newUiOptions ^= View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
    newUiOptions ^= View.SYSTEM_UI_FLAG_FULLSCREEN;
    newUiOptions ^= View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
    getWindow().getDecorView().setSystemUiVisibility(newUiOptions);
}

And it only happens when you enter the App from App Icon, if you comeback from android task view it works nice. I gave up but if you have any ideas I would try anything.

Answer

After a lot of testing I have found the solution.

I have had to remove the fullscreen property from xml styles, that was applying some internal states that broke my app screen.

And now I have to manage the state just in code.

  1. Remove android:fitsSystemWindows="true" so my layout doesn’t leave extra space for status bar.

  2. Remove android:windowFullscreen from style, now it looks like this:

    <style name="AppTheme.FullScreen" parent="Theme.AppCompat.NoActionBar">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
    </style>
    
  3. Change code of flags to override current state on onResume(), I was adding flags to current state, don’t ask me why, probably some copy-paste fail:

    private void hideSystemUI() {
        int newUiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
            View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
        getWindow().getDecorView().setSystemUiVisibility(newUiOptions);
    }
    
We are here to answer your question about Android glitch opening app with full screen and list views - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji