Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable the navigation bar slide animation when going fullscreen?

I have an activity that goes to another full screen activity. However, when transitioning from this activity to my full screen activity, the navigation bar slides down instead of disappearing instantly. I've inflated a full-screen window in the second activity, but because of the slow sliding animation, it resizes 1 second later after the animation has completed instead of being inflated to full-screen immediately. Therefore, I need the animation to disappear instantly. I've tried

<item name="android:windowAnimationStyle">@null</item>

and

overridePendingTransition(0, 0);

and

Transition fade = new Fade();
fade.excludeTarget(android.R.id.navigationBarBackground, true);
getWindow().setEnterTransition(fade);

with no luck.

On the Windows side, I've tried

WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS 
WindowManager.LayoutParams.FLAG_FULLSCREEN 
WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN

How I hide the navbar: View.SYSTEM_UI_FLAG_HIDE_NAVIGATION

like image 474
Kyle Avatar asked Jan 24 '16 14:01

Kyle


1 Answers

I think, I nailed it:

enter image description here

FullscreenActivity class:

public class FullscreenActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        View decorView = getWindow().getDecorView();
        int uiOptions = View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
        decorView.setSystemUiVisibility(uiOptions);
        ActionBar actionBar = getSupportActionBar();
        if (actionBar != null) {
            actionBar.hide();
        }

        setContentView(R.layout.activity_fullscreen);
    }
}

Manifest:

    <activity
        android:name=".FullscreenActivity"
        android:configChanges="orientation|keyboardHidden|screenSize"
        android:label="@string/title_activity_fullscreen"
        android:theme="@style/FullscreenTheme"/>

Styles:

<style name="FullscreenTheme" parent="AppTheme">
    <item name="android:statusBarColor">@android:color/transparent</item>
    <item name="android:actionBarStyle">@style/FullscreenActionBarStyle</item>
    <item name="android:windowActionBarOverlay">true</item>
    <item name="android:windowBackground">@null</item>
    <item name="metaButtonBarStyle">?android:attr/buttonBarStyle</item>
    <item name="metaButtonBarButtonStyle">?android:attr/buttonBarButtonStyle</item>
</style>

NB! Setting StatusBar colour required API 21. For the older versions, to "hide" StatusBar, you need use:

        int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                | View.SYSTEM_UI_FLAG_FULLSCREEN;

as uiOptions in the code above. (it'll cause quite quick resizing, though).

I hope, it helps

like image 75
Konstantin Loginov Avatar answered Oct 14 '22 12:10

Konstantin Loginov