2

I use NoActionBar them to activity like this:

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

and i try to set full screen like this:

 @Override
public void onWindowFocusChanged(boolean hasFocus) {
    super.onWindowFocusChanged(hasFocus);
    AppLog.Log(TAG, "hasFocus: " + hasFocus);
    if (hasFocus) {
        getWindow().getDecorView().setSystemUiVisibility(
                View.SYSTEM_UI_FLAG_LOW_PROFILE
                | View.SYSTEM_UI_FLAG_FULLSCREEN
                | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
                | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
    }
}

but my snackbar height is doubled like this:

enter image description here

why snackbar height is doubled in NoActionBar themes??

Iman Marashi
  • 4,677
  • 33
  • 48
  • I think it is due to you hiding the navigation and not due to the actionbar being missing. What happens if you remove the full screen flags and this: | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) – dazza5000 Feb 15 '18 at 19:53

1 Answers1

3

Your snackbar is taking up the space of the previous Actionbar. Use this to fix it:

final Snackbar snackbar = Snackbar.make(findViewById(R.id.fullscreen_content),
            message, Snackbar.LENGTH_LONG);

View snackbarView = snackbar.getView();

//One way of getting the height of the navBar
int navbarHeight = getNavigationBarSize(this).y;

//The LayoutParams of the layout you are using
CoordinatorLayout.LayoutParams parentParams = (CoordinatorLayout.LayoutParams) snackbarView.getLayoutParams();
    parentParams.setMargins(0, 0, 0, 0 - ScreenUtils.getNavigationBarHeight(activity));
    snackbarView.setLayoutParams(parentParams);

snackbar.show();

Explanation: There are 2 ways to get the height of the Navbar.

getNavigationBarSize(this).y;

or

ScreenUtils.getNavigationBarHeight(activity));

Use either of then and subtract that amount from the margin bottom of the parent layout.

Use appropriate layout params like RelativeLayout.LayoutParams or LinearLayout.LayoutParams if you are using Relative or Linear layout

Ratul Bin Tazul
  • 1,908
  • 1
  • 11
  • 22
  • and how to use **navbarHeight**? – Iman Marashi Feb 15 '18 at 20:20
  • You don't need to use it. It's just another way of getting the height of the ActionBar – Ratul Bin Tazul Feb 15 '18 at 21:08
  • I use this to get the navigation bar height: https://stackoverflow.com/a/20264361/3260008 – Amos Oct 05 '18 at 06:56
  • This is not actually changing the height of the Snackbar, it's just adding a negative margin and hiding the bottom half of it. As a result you lose the rounded corners and it doesn't look correct so this solution is not strictly correct. – Philio Jul 03 '19 at 16:00