gpt4 book ai didi

android - NoActionBar 主题中的 snackbar 高度加倍

转载 作者:搜寻专家 更新时间:2023-11-01 08:22:44 25 4
gpt4 key购买 nike

我使用 NoActionBar 它们来进行这样的 Activity :

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

但我的 snackbar 高度是这样加倍的:

enter image description here

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

最佳答案

您的 snackbar 占用了之前 Actionbar 的空间。用这个来修复它:

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

使用 then 中的任何一个并从父布局的 ma​​rgin bottom 中减去该数量。

如果您使用相对或线性布局,请使用适当的布局参数,如 RelativeLayout.LayoutParamsLinearLayout.LayoutParams

关于android - NoActionBar 主题中的 snackbar 高度加倍,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48815135/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com