React-Native Button style not work

前端 未结 9 1073
傲寒
傲寒 2020-12-24 10:33

Import_this

import {AppRegistry, Text, View, Button, StyleSheet} from \'react-native\';

This my

相关标签:
9条回答
  • 2020-12-24 10:40

    We can use buttonStyle prop now.
    https://react-native-training.github.io/react-native-elements/docs/button.html#buttonstyle

    0 讨论(0)
  • 2020-12-24 10:42

    Instead of using button . you can use Text in react native and then make in touchable

    <TouchableOpacity onPress={this._onPressButton}> 
       <Text style = {'your custome style'}>
           button name
       </Text>
    </TouchableOpacity >
    
    0 讨论(0)
  • 2020-12-24 10:44

    React Native buttons are very limited in the option they provide.You can use TouchableHighlight or TouchableOpacity by styling these element and wrapping your buttons with it like this

                 <TouchableHighlight 
                    style ={{
                        height: 40,
                        width:160,
                        borderRadius:10,
                        backgroundColor : "yellow",
                        marginLeft :50,
                        marginRight:50,
                        marginTop :20
                    }}>
                <Button onPress={this._onPressButton}            
                title="SAVE"
                accessibilityLabel="Learn more about this button"
              /> 
              </TouchableHighlight> 
    

    You can also use react library for customised button .One nice library is react-native-button (https://www.npmjs.com/package/react-native-button)

    0 讨论(0)
  • 2020-12-24 10:45

    Only learning myself, but wrapping in a View may allow you to add styles around the button.

    const Stack = StackNavigator({
      Home: {
        screen: HomeView,
        navigationOptions: {
          title: 'Home View'
        }
      },
      CoolView: {
        screen: CoolView,
        navigationOptions: ({navigation}) => ({
          title: 'Cool View',
          headerRight: (<View style={{marginRight: 16}}><Button
            title="Cool"
            onPress={() => alert('cool')}
          /></View>
        )
        })
      }
    })
    
    0 讨论(0)
  • 2020-12-24 10:47

    If you do not want to create your own button component, a quick and dirty solution is to wrap the button in a view, which allows you to at least apply layout styling.

    For example this would create a row of buttons:

    <View style={{flexDirection: 'row'}}>
        <View style={{flex:1 , marginRight:10}} >
            <Button title="Save" onPress={() => {}}></Button>
        </View>
        <View style={{flex:1}} >
            <Button title="Cancel" onPress={() => {}}></Button>
        </View>
    </View>
    
    0 讨论(0)
  • 2020-12-24 10:50

    The React Native Button is very limited in what you can do, see; Button

    It does not have a style prop, and you don't set text the "web-way" like <Button>txt</Button> but via the title property <Button title="txt" />

    If you want to have more control over the appearance you should use one of the TouchableXXXX' components like TouchableOpacity They are really easy to use :-)

    0 讨论(0)
提交回复
热议问题