javascript - How to set the background color of Tab.Screen? - Stack Overflow

As you can see below, I've tried many ways of setting the background color to transparent like thi

As you can see below, I've tried many ways of setting the background color to transparent like this (UI required), all to no avail. The background remains grey-ish like the image

  <Tab.Navigator screenOptions={{
    tabBarShowLabel: false,
    swipeEnabled: false,
    tabBarShowIcon: true,
    tabBarItemStyle: { width: iconwidth },
    tabBarStyle: { backgroundColor: 'transparent', paddingBottom: 10},
    tabBarContentContainerStyle: {backgroundColor : 'transparent', display: 'flex', justifyContent: 'center', alignItems: 'center'},
    tabBarPressColor: '#3C60AA',
    tabBarIndicatorStyle: {width: iconwidth , height: 5, backgroundColor: '#3C60AA', borderRadius: 20, marginStart: iconwidth *0.61},
    lazy: true,
    lazyPlaceholder: () => <POTab_lazy/>
  }}>

    <Tab.Screen name="POTab_1" ponent={POTab_1} options={{ tabBarAccessibilityLabel: 'Info',tabBarIcon: ({ tintColor }) => ( <Image source={require('../../assets/icon_info.png')} style={{width: 30, height: 30 }}/>), }}/>
    <Tab.Screen name="POTab_2" ponent={POTab_2} options={{tabBarAccessibilityLabel: 'File',tabBarIcon: ({ tintColor }) => ( <Image source={require('../../assets/icon_file.png')} style={{width: 30, height: 30 }}/>),}}/>
    <Tab.Screen name="POTab_3" ponent={POTab_3} options={{tabBarAccessibilityLabel: 'Attach',tabBarIcon: ({ tintColor }) => ( <Image source={require('../../assets/icon_attach.png')} style={{width: 30, height: 30 }}/>),}}/>
    <Tab.Screen name="POTab_4" ponent={POTab_4} options={{tabBarAccessibilityLabel: 'Link',tabBarIcon: ({ tintColor }) => ( <Image source={require('../../assets/icon_link.png')} style={{width: 30, height: 30 }}/>),}}/>
    <Tab.Screen name="POTab_5" ponent={POTab_5} options={{tabBarAccessibilityLabel: 'Timer',tabBarIcon: ({ tintColor }) => ( <Image source={require('../../assets/icon_timer.png')} style={{width: 30, height: 30 }}/>),}}/>
  </Tab.Navigator>

); }

POTab_1.js code looks like this

<ScrollView showsVerticalScrollIndicator={false}>
  <View style={{ flex: 1, justifyContent: 'flex-start', alignItems: 'flex-start', padding: 20 }}>
    
    <View style={{marginBottom: 15}}>
      <Text style={{color: 'grey', fontFamily: 'Poppins-Regular', lineHeight: 20}}>Purchase Order</Text>
      <Text style={{color: 'black', fontFamily: 'Poppins-Bold'}}>450004892</Text>
    </View>

    <View style={{marginBottom: 15}}>
      <Text style={{color: 'grey', fontFamily: 'Poppins-Regular', lineHeight: 20}}>Vendor id</Text>
      <Text style={{color: 'black', fontFamily: 'Poppins-Bold'}}>0003300000</Text>
    </View>

    <View style={{marginBottom: 15}}>
      <Text style={{color: 'grey', fontFamily: 'Poppins-Regular, lineHeight: 20'}}>Vendor Name</Text>
      <Text style={{color: 'black', fontFamily: 'Poppins-Bold'}}>ITT Texas</Text>
    </View>

    <View style={{marginBottom: 15}}>
      <Text style={{color: 'grey', fontFamily: 'Poppins-Regular, lineHeight: 20'}}>Item No</Text>
      <Text style={{color: 'black', fontFamily: 'Poppins-Bold'}}>00010</Text>
    </View>

  </View>
</ScrollView>

package.json

@react-navigation/material-top-tabs: "^6.2.2"

react-native-pager-view: "^5.4.25"

react-native-tab-view: "^3.1.1"

for material top bar navigator reference, look here

As you can see below, I've tried many ways of setting the background color to transparent like this (UI required), all to no avail. The background remains grey-ish like the image

  <Tab.Navigator screenOptions={{
    tabBarShowLabel: false,
    swipeEnabled: false,
    tabBarShowIcon: true,
    tabBarItemStyle: { width: iconwidth },
    tabBarStyle: { backgroundColor: 'transparent', paddingBottom: 10},
    tabBarContentContainerStyle: {backgroundColor : 'transparent', display: 'flex', justifyContent: 'center', alignItems: 'center'},
    tabBarPressColor: '#3C60AA',
    tabBarIndicatorStyle: {width: iconwidth , height: 5, backgroundColor: '#3C60AA', borderRadius: 20, marginStart: iconwidth *0.61},
    lazy: true,
    lazyPlaceholder: () => <POTab_lazy/>
  }}>

    <Tab.Screen name="POTab_1" ponent={POTab_1} options={{ tabBarAccessibilityLabel: 'Info',tabBarIcon: ({ tintColor }) => ( <Image source={require('../../assets/icon_info.png')} style={{width: 30, height: 30 }}/>), }}/>
    <Tab.Screen name="POTab_2" ponent={POTab_2} options={{tabBarAccessibilityLabel: 'File',tabBarIcon: ({ tintColor }) => ( <Image source={require('../../assets/icon_file.png')} style={{width: 30, height: 30 }}/>),}}/>
    <Tab.Screen name="POTab_3" ponent={POTab_3} options={{tabBarAccessibilityLabel: 'Attach',tabBarIcon: ({ tintColor }) => ( <Image source={require('../../assets/icon_attach.png')} style={{width: 30, height: 30 }}/>),}}/>
    <Tab.Screen name="POTab_4" ponent={POTab_4} options={{tabBarAccessibilityLabel: 'Link',tabBarIcon: ({ tintColor }) => ( <Image source={require('../../assets/icon_link.png')} style={{width: 30, height: 30 }}/>),}}/>
    <Tab.Screen name="POTab_5" ponent={POTab_5} options={{tabBarAccessibilityLabel: 'Timer',tabBarIcon: ({ tintColor }) => ( <Image source={require('../../assets/icon_timer.png')} style={{width: 30, height: 30 }}/>),}}/>
  </Tab.Navigator>

); }

POTab_1.js code looks like this

<ScrollView showsVerticalScrollIndicator={false}>
  <View style={{ flex: 1, justifyContent: 'flex-start', alignItems: 'flex-start', padding: 20 }}>
    
    <View style={{marginBottom: 15}}>
      <Text style={{color: 'grey', fontFamily: 'Poppins-Regular', lineHeight: 20}}>Purchase Order</Text>
      <Text style={{color: 'black', fontFamily: 'Poppins-Bold'}}>450004892</Text>
    </View>

    <View style={{marginBottom: 15}}>
      <Text style={{color: 'grey', fontFamily: 'Poppins-Regular', lineHeight: 20}}>Vendor id</Text>
      <Text style={{color: 'black', fontFamily: 'Poppins-Bold'}}>0003300000</Text>
    </View>

    <View style={{marginBottom: 15}}>
      <Text style={{color: 'grey', fontFamily: 'Poppins-Regular, lineHeight: 20'}}>Vendor Name</Text>
      <Text style={{color: 'black', fontFamily: 'Poppins-Bold'}}>ITT Texas</Text>
    </View>

    <View style={{marginBottom: 15}}>
      <Text style={{color: 'grey', fontFamily: 'Poppins-Regular, lineHeight: 20'}}>Item No</Text>
      <Text style={{color: 'black', fontFamily: 'Poppins-Bold'}}>00010</Text>
    </View>

  </View>
</ScrollView>

package.json

@react-navigation/material-top-tabs: "^6.2.2"

react-native-pager-view: "^5.4.25"

react-native-tab-view: "^3.1.1"

for material top bar navigator reference, look here

Share Improve this question edited Aug 19, 2022 at 17:18 mharis404 asked Aug 19, 2022 at 17:10 mharis404mharis404 431 silver badge6 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 9

If you're trying to change the screens, not the tab bar itself, I found setting sceneContainerStyle to be the way to do it:

<Tab.Navigator sceneContainerStyle={{backgroundColor: 'transparent'}} >

If you want to set background color for the whole tab bar, then we need to provide the style in tabBarOptions prop to the Tab.Navigator.

Consider the following code snippet.

<Tab.Navigator
  tabBarOptions={{
    style: {
      backgroundColor: 'transparent',
    }
  }}>

Updated your code to include tabBarOptions

<Tab.Navigator screenOptions={{
    tabBarShowLabel: false,
    swipeEnabled: false,
    tabBarShowIcon: true,
    tabBarItemStyle: { width: iconwidth },
    tabBarStyle: { backgroundColor: 'transparent', paddingBottom: 10},
    tabBarContentContainerStyle: {backgroundColor : 'transparent', display: 'flex', justifyContent: 'center', alignItems: 'center'},
    tabBarPressColor: '#3C60AA',
    tabBarIndicatorStyle: {width: iconwidth , height: 5, backgroundColor: '#3C60AA', borderRadius: 20, marginStart: iconwidth *0.61},
    lazy: true,
    lazyPlaceholder: () => <POTab_lazy/>
  }}
  tabBarOptions={{
    style: {
      backgroundColor: 'transparent',
    }
  }}>

    <Tab.Screen name="POTab_1" ponent={POTab_1} options={{ tabBarAccessibilityLabel: 'Info',tabBarIcon: ({ tintColor }) => ( <Image source={require('../../assets/icon_info.png')} style={{width: 30, height: 30 }}/>), }}/>
    <Tab.Screen name="POTab_2" ponent={POTab_2} options={{tabBarAccessibilityLabel: 'File',tabBarIcon: ({ tintColor }) => ( <Image source={require('../../assets/icon_file.png')} style={{width: 30, height: 30 }}/>),}}/>
    <Tab.Screen name="POTab_3" ponent={POTab_3} options={{tabBarAccessibilityLabel: 'Attach',tabBarIcon: ({ tintColor }) => ( <Image source={require('../../assets/icon_attach.png')} style={{width: 30, height: 30 }}/>),}}/>
    <Tab.Screen name="POTab_4" ponent={POTab_4} options={{tabBarAccessibilityLabel: 'Link',tabBarIcon: ({ tintColor }) => ( <Image source={require('../../assets/icon_link.png')} style={{width: 30, height: 30 }}/>),}}/>
    <Tab.Screen name="POTab_5" ponent={POTab_5} options={{tabBarAccessibilityLabel: 'Timer',tabBarIcon: ({ tintColor }) => ( <Image source={require('../../assets/icon_timer.png')} style={{width: 30, height: 30 }}/>),}}/>
  </Tab.Navigator>

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744019355a4544578.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信