简体   繁体   English

如何在 react-native 中的按钮上添加图标

[英]How to add an icon to a button in react-native

I'm creating a button using <TouchableOpacity> on react-native.我在 react-native 上使用<TouchableOpacity>创建一个按钮。

            <View style = {{
                flex: 1,
                justifyContent: 'flex-end',
                paddingBottom: 30,
            }}>
                <TouchableOpacity 
                    style = {{
                        justifyContent: 'center',
                        padding: 10,
                        height: 30,
                        width: '100%',
                        flexDirection: 'row',
                    }}
                    onPress = {() => {
                        this.props.navigation.navigate('Login');
                        firebase.auth().signOut();
                    }}>
                    <Icon
                        name = 'log-out'
                        type = 'feather'
                        color = 'black' />
                    <Text style = {{
                        fontWeight: 100,
                        fontSize: 20
                    }}>
                        LOGOUT
                    </Text>
                </TouchableOpacity>
            </View>

The output output

How do I align the icon and text to the left?如何将图标和文本左对齐? And is there a way I can make the icon fully appear?有没有办法让图标完全出现?

You can use images that works same as icons您可以使用与图标相同的图像
You can download some great icons from google fonts icons您可以从 google fonts 图标下载一些很棒的图标
check this out https://fonts.google.com/icons看看这个https://fonts.google.com/icons

So your code will be所以你的代码将是

<View style = {{
            flex: 1,
            justifyContent: 'flex-end',
            paddingBottom: 30,
        }}>
            <TouchableOpacity 
                style = {{
                    justifyContent: 'center',
                    padding: 10,
                    height: 30,
                    width: '100%',
                    flexDirection: 'row',
                }}
                onPress = {() => {
                    this.props.navigation.navigate('Login');
                    firebase.auth().signOut();
                }}>
                
                    <Image src={source to your image} style={{add your style}}/>
             
            </TouchableOpacity>
        </View>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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