android - getStableInsetTop() 总是返回 0?
问题描述
我想获得稳定的系统 UI 插图。从中获取系统 UI(导航栏和状态栏)的高度和宽度。
问题:我使用了getSystemWindowInsetTop()
windowInsets 类的方法,但是当屏幕进入沉浸式模式并且系统 UI(导航栏和状态栏)隐藏时它变为零。但我想要稳定的插图,这就是我尝试使用getStableInsetTop()
方法的原因,它总是返回 0。
代码:
binding.lytParent.setOnApplyWindowInsetsListener((view, windowInsets) -> {
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT
, windowInsets.getStableInsetTop()
);
binding.vTopMargin.setLayoutParams(params);
});
注意:我已经fitSystemWindows="true"
在 XML 的父布局中添加了该属性。getSystemWindowInsetTop()
工作正常并返回 Inset 值,但问题是它的值随系统 UI(导航栏和状态栏)的可见性而变化。
解决方案
推荐阅读
- clojure - 在 Clojure 中使用尼安德特人时出现 MKL 库错误
- python - 排序时嵌套的dict抛出关键错误
- c# - 如何在没有链接文本的情况下在 MVC C# 中使用 @Action 链接
- java - 如何让(轮盘赌)日程变慢
- mysql - 无法从 AWS Lambda 函数连接到在 AWS EC2 上运行的 MySQL 实例
- mysql - LOAD DATA LOCAL INFILE 操作一些日期列
- go - 如何使 goroutines 与匿名函数一起工作,在循环中返回值
- sql - 查询具有多个同名数组的表
- chef-infra - 刀命令的ChefDk问题
- soap - WSO2 身份服务器密码更改,出现问题“无法访问用户的目录服务”