android - Android P 的 Android 导航栏可见性 - 检测基于手势的导航
问题描述
如何检测导航栏(对于无 Bazel 设备)是否可见?我尝试使用Resource Identifier、System UI Flag和KeyCharacterMap为导航栏使用不同的解决方案,但它对我不起作用。在Andorid P中,手势导航可用,它将隐藏导航栏,导航功能将使用该手势运行。有什么解决方案可以检测到这一点吗?
解决方案
我使用两种手势导航方法在小米设备上测试了这段代码,对我来说它正在工作:
Point p = new Point();
getWindow().getWindowManager().getDefaultDisplay().getRealSize(p);
ConstraintLayout container = findViewById(your activity main view (e.g linearLayout));
final TypedArray styledAttributes = getTheme().obtainStyledAttributes(
new int[]{android.R.attr.actionBarSize});
int mActionBarSize = (int) styledAttributes.getDimension(0, 0);
int height = container.getMeasuredHeight();
int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
int result = 0;
if (resourceId > 0) {
result = getResources().getDimensionPixelSize(resourceId);
}
if (height + mActionBarSize + result >= p.y) {
//you have fullscreen gesture navigation
}else{
//navigation bar or similiar
}
这是因为应用程序现在可以在屏幕上显示更大的尺寸,因此它仅在手势导航方法不使“导航栏”背景时才有效。
只要确保在 main 已经加载并且可见时使用它,否则它将返回 0。
推荐阅读
- java - Java:lambda 表达式连接多个字符串参数
- node.js - 当我控制台 req.body 它时,给我所有具有值的属性,但是当我获得单个属性值时,给我错误未定义
- javascript - TYPO3 在同一个容器中打开 actionlink
- javascript - 通过 ng-repeat 循环嵌套数组并创建表行
- sql - 使用 SQL 创建查询哪个网格位置在商店中产生最多收入
- python - 如何在 python 中绘制的图形中获得白色边框?
- c# - 我正在寻找一种惰性的、线程安全的实现来缓存昂贵计算的第一个非空结果
- html - 将 CSS 应用于页面上的特殊字符
- java - Settings.Secure.INSTALL_NON_MARKET_APPS 现在已弃用我可以使用什么?
- php - 如何从其他 PHP 服务器获得对 Rails 服务器的响应