【问题标题】:React Native get correct status bar height on androidReact Native 在 android 上获得正确的状态栏高度
【发布时间】:2019-05-29 11:16:30
【问题描述】:

我正在尝试使用 React Native 的 StatusBar.currentHeight https://facebook.github.io/react-native/docs/statusbar 获取 Android 设备上的状态栏高度。在像素 2 上,该变量是 24,而实际上状态栏高度是 19。有谁知道在所有使用 React Native 的设备上获得正确状态栏高度的方法?

【问题讨论】:

  • 在我的例子中,StatusBar.currentHeight 是 49.09090805053711,而实际上是 62,在 Pixel 4 模拟器上。你最终是如何解决这个问题的?
  • @Scottw 有这方面的消息吗?您找到解决方案了吗?

标签: android react-native


【解决方案1】:

您可以尝试下载expo-constants 模块。

import Constants from 'expo-constants';
...
const STATUSBAR_HEIGHT = Constants.statusBarHeight

【讨论】:

    【解决方案2】:
    import { Dimensions, StatusBar } from 'react-native'
    
    const { height: SCREEN_HEIGHT, width: SCREEN_WIDTH } = Dimensions.get('window');
    const STATUSBAR_HEIGHT = StatusBar.currentHeight;
    

    【讨论】:

    • StatusBar.currentHeight 似乎在某些设备上报告了错误的信息。如前所述,当高度实际为 19 时,像素 2 上的问题将返回 24
    猜你喜欢
    • 2020-08-05
    • 2016-05-27
    • 2018-02-17
    • 1970-01-01
    • 2012-12-13
    • 1970-01-01
    • 2013-12-15
    • 2017-06-01
    • 2020-07-19
    相关资源
    最近更新 更多