Screen of a strange black rectangle on the screen

UPDATE: Finally, find a slightly hacky solution. But this is not acceptable to me. Any ideas can be helpful.

I have a Splash Screen Activity and I am not using setContentView (). I have set the background from styles.xml using android: windowBackground

When the splash screen starts, a black rectangle appears out of nowhere located at the bottom left of the screen. The height is exactly the same height as the NavigationBar, starts at the left of the screen and ends at the center of the screen.

This black rectangle only appears on devices that have a navigation bar . Not physical buttons. And it is also visible only when trying to hide or show the navigation bar while FullScreen is active .

QUESTION: What could be the cause of this error? How can I solve it?

You can see the entire event below. (Moving the Splash Screen to the Login Screen)

giphy.gif

Here's my style of splash activity:

<style name="SplashTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="android:windowBackground">@drawable/background_splash</item>
    <item name="windowNoTitle">true</item>
    <item name="windowActionBar">false</item>
    <item name="android:windowFullscreen">true</item>
    <item name="android:windowContentOverlay">@null</item>
</style>

      

background_splash.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    //Tried different colored layer at bottom level but did not affect
    <item>
        <shape android:shape="rectangle">
            <solid android:color="@color/grey_Dark"/>
        </shape>
    </item>

    //Background image
    <item
        android:drawable="@drawable/bg"
        android:gravity="center"/>

    //9-patch Logo at the center
    <item
        android:drawable="@drawable/splash_logo"
        android:gravity="center"/>

</layer-list>

      

ActivitySplash

public class ActivitySplash extends BaseActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        final View decorView = getWindow().getDecorView();
        decorView.setSystemUiVisibility(
            View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION // hide nav bar
                    | View.SYSTEM_UI_FLAG_FULLSCREEN
                    | View.SYSTEM_UI_FLAG_IMMERSIVE);


        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                Intent intent = new Intent(ActivitySplash.this, ActivityLogin.class);
                startActivity(intent);
                finish();
            }
        }, 2000);

    }
}

      

+3


source to share


1 answer


Finally, find a slightly hacky solution. But this is not acceptable to me. Any ideas might be helpful.

First, use the "Layout inspector" and get this output:

enter image description here

An unwanted Strange View is generated in DecorView after launching splash activity.

It flashes after half a second and disappears.

After flashing, if the user triggers the screen to display the navigation bar, this strange view reappears (permanently).



The flashing view disappeared after adding

<item name="android:windowIsTranslucent">true</item>

      

into my style of action.

The other part is more difficult. Added OnHierarchyChangeListener element to DecorView for activity. Dropped my DecorView in a FrameLayout and will override the onChildViewAdded () callback to remove all children once added to the DecorView .

final FrameLayout myDecorView = (FrameLayout) decorView;
myDecorView.setOnHierarchyChangeListener(new ViewGroup.OnHierarchyChangeListener() {
    @Override
    public void onChildViewAdded(View parent, View child) {
        myDecorView.removeView(child);
    }

    @Override
    public void onChildViewRemoved(View parent, View child) {

    }
});

      

+1


source







All Articles