简体   繁体   中英

React Native - Vector icons in Navigation bar

In my React Native app, I would like to use Vector Icons as navigation bar buttons. For that, I'm using: https://github.com/oblador/react-native-vector-icons For navigation: https://reactnavigation.org/

I managed to set the icons as well, but when I tap the buttons, I get an unwanted effect where the background turns black. Is there a way how I can keep the background color transparent also when the button's pressed?

Here's my code:

static navigationOptions = ({ navigation }) => {
    const { params } = navigation.state

    return {
    headerTitle: "Blog posts",
    headerRight: (            
        <Icon.Button name="quote-right" backgroundColor="transparent" color="black" onPress={() => params.postComment()}>
            <Text style={{fontSize: 15}}></Text>
        </Icon.Button>            
      ),
    headerLeft: (                                     
        <Icon.Button name="navicon" backgroundColor="transparent" color="black" onPress={() => params.postComment()}>
            <Text style={{fontSize: 15}}></Text>
        </Icon.Button>                                                                     
      ),
    };
};

And here's what I got:

在此处输入图片说明

The prop you are looking for is underlayColor , that's the one you should set to transparent .

<Icon.Button
   name="quote-right"
   backgroundColor="transparent"
   underlayColor="transparent" // This one
   color="black"
   onPress={() => params.postComment()}
>
     <Text style={{fontSize: 15}}></Text>
</Icon.Button>  

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM