【问题标题】:How can we set background color and tint color only for android using react navigation?我们如何使用反应导航仅为 android 设置背景颜色和色调颜色?
【发布时间】:2017-03-30 06:59:03
【问题描述】:

我正在尝试使用“react navigation”仅在 android 中更改标签栏的背景颜色。有可能吗?

我使用下面的 tabBarOptions,但它会在 iOS 和 Android 中更改背景颜色,但我的要求是仅在 Android 中更改颜色并且它应该在 iOS 中保持默认,

{ tabBarOptions: { 风格: { 背景颜色:'#2D61A9', } } }

提前致谢。

【问题讨论】:

    标签: react-native react-navigation


    【解决方案1】:

    您可以使用Platform see here 设置平台操作系统特定的样式。

    以下应该工作。

    {
      tabBarOptions : {
        style: {
          Platform.select({
          android: {
            backgroundColor: '#2D61A9',
          },
        }
      }
    }
    

    【讨论】:

      【解决方案2】:

      使用平台的简单 ios 检查

      import { Platform } from 'react-native';
      
      const style = Platform.OS === 'ios' ? {} : {backgroundColor: '#2D61A9'}
      
      { tabBarOptions: { style } }
      
      

      【讨论】:

      • 为什么你更喜欢这种语法而不是三年前留下的类似答案?它为实施者提供了什么好处?您介意使用该信息编辑您的答案以帮助将其与现有答案区分开来吗?
      • 并且不起作用,它不完整,Platform.select返回一个复杂的对象,你仍然需要传播它例如...Platform.select()上面的代码没有关闭()即使有,它也会导致style: { {backgroundColor: '#2D61A9' }} 而不是style: {backgroundColor: '#2D61A9'} @JeremyCaney
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-10-04
      • 1970-01-01
      • 2018-06-23
      • 1970-01-01
      • 2017-12-29
      • 2013-08-04
      • 1970-01-01
      相关资源
      最近更新 更多