Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
React native Android导航栏高度反应本机_React Native - Fatal编程技术网

React native Android导航栏高度反应本机

React native Android导航栏高度反应本机,react-native,React Native,我正试图让Android底部的工具栏(有后退按钮的工具栏)与RN一起工作。我做了以下工作: Dimensions.get('window').height 我用这根杆子得到了高度!因为它可能在那里,也可能不在那里,而且可能更大或更大,这取决于设置,这对我来说是个大问题。如果你指的是顶部的状态栏 根据你可以使用 import { StatusBar } from 'react-native'; 然后在代码中 StatusBar.currentHeight 更新 您可以使用此模块获取此信息 要

我正试图让Android底部的工具栏(有后退按钮的工具栏)与RN一起工作。我做了以下工作:

Dimensions.get('window').height

我用这根杆子得到了高度!因为它可能在那里,也可能不在那里,而且可能更大或更大,这取决于设置,这对我来说是个大问题。

如果你指的是顶部的状态栏

根据你可以使用

import { StatusBar } from 'react-native';
然后在代码中

StatusBar.currentHeight
更新

您可以使用此模块获取此信息


要检测是否存在软安卓导航,您可以使用此模块。

我使用下面的表格进行检测:

// RN version:0.57.0
let deviceH = Dimensions.get('screen').height;
// the value returned does not include the bottom navigation bar, I am not sure why yours does.
let windowH = Dimensions.get('window').height;
let bottomNavBarH = deviceH - windowH;
首先我们需要进口

import { Dimensions , StatusBar } from 'react-native';
窗口高度=
尺寸。获取('window')。高度
屏幕高度=
尺寸。获取('screen')。高度
StatusBarHeight=StatusBar.currentHeight

窗口高度=屏幕高度-导航栏高度

当我们想在页面底部实现浮动按钮时,为该高度设置WindowHeight,并为子元素设置
bottom:StatusBar.currentHeight

当我们没有导航栏时, 窗高=屏幕高度

  • 在iOS设备中,
    屏幕高度===windowHeight
  • 在具有底部导航栏的Android设备中,
    屏幕高度===windowHeight+statusBarHeight+bottomNavigatorBarHeight
  • 在没有底部导航栏的Android设备中,
    bottomNavigatorBarHeight
    为零

首先,如其他答案所述,使用Android中的react native Dimensions API窗口高度=屏幕高度-(状态栏高度+导航栏高度)

经过几个小时的调查,我发现在一些安卓设备中,API给出了错误的窗口高度数字

的解决方案是使用[react native extra dimensions android][1]

[1] :它为您提供以下信息:

REAL_WINDOW_HEIGHT-屏幕的实际高度,包括系统装饰元素 REAL_WINDOW_WIDTH-屏幕的实际宽度,包括系统装饰元素 状态栏高度-状态栏的高度 SOFT_MENU_BAR_HEIGHT-软菜单栏的高度(大多数新Android设备支持)


然后,您可以计算窗口高度:真实窗口高度-(状态栏高度+软菜单栏高度)

OP指的是带有返回和主页按钮的屏幕导航栏,而不是状态栏。谢谢!有没有办法知道它是否存在?是的,你可以用这个,它似乎起到了作用。我还没来得及仔细检查,尤其是没有酒吧的时候。现在就可以了!谢谢!可能是你正在寻找的,我认为这个方法的问题是它也会考虑到状态栏的高度。例如,我打开了手势导航,因此没有导航栏可显示,但状态栏仍返回25的高度。对我来说,这与隐藏状态栏时显示的高度相同?我发现Android上的导航栏似乎略有不同。Android的较新版本这似乎是正确的,较旧版本的
windowHeight
似乎也包含了
statusBarHeight
,这很让人困惑。嗨,你介意分享更多细节吗?您使用哪个版本和设备型号?使用基本公式设置最小CSS高度
维度。获取(“窗口”)。高度-页眉高度-页脚高度
(其中页眉高度=400,页脚高度=200)这是较新设备(如诺基亚8.1和OnePlus6T手机)屏幕高度的100%。在我使用的所有模拟器和Galaxy S6上,我需要减去
statusBarHeight
,使其精确到100%
import { Dimensions , StatusBar } from 'react-native';

const screenHeight = Dimensions.get('screen').height;
const windowHeight = Dimensions.get('window').height;
const navbarHeight = screenHeight - windowHeight + StatusBar.currentHeight;
import {Dimensions, StatusBar} from 'react-native'; 

const DEVICE_HEIGHT = Dimensions.get('screen').height;
const STATUS_BAR = StatusBar.statusBarHeight || 24; 
const WINDOW_HEIGHT = Dimensions.get('window').height;