快餐栏高度在NoActionBar主题中加倍

问题描述 投票:2回答:1

我将NoActionBar用于这样的活动:

 <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>

我试着像这样设置全屏:

 @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);
    }
}

但我的小吃吧高度加倍如下:

enter image description here

为什么在NoActionBar主题中snackbar高度加倍?

android android-snackbar
1个回答
3
投票

您的快餐栏占用了前一个操作栏的空间。用它来修复它:

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();

说明:有两种方法可以获得Navbar的高度。

getNavigationBarSize(this).y;

要么

ScreenUtils.getNavigationBarHeight(activity));

使用其中之一并从父布局的边距底部减去该数量。

如果使用相对或线性布局,请使用相应的布局参数,如RelativeLayout.LayoutParams或LinearLayout.LayoutParams

© www.soinside.com 2019 - 2024. All rights reserved.