React native 我正在尝试使用react native在按钮上实现阴影效果,但不起作用。有人能帮我吗?

React native 我正在尝试使用react native在按钮上实现阴影效果,但不起作用。有人能帮我吗?,react-native,React Native,自定义按钮类 从“React”导入React,{Component}; 从“react native”导入{平台、样式表、文本、视图、按钮、TouchableOpacity} 导出默认类FlatButton扩展组件{ 陈述={ 背景颜色:“#f01d71”, 背景色2:“#f01d71”, 答:错,, }) changeColor(){ 如果(!this.state.pressed){ setState({pressed:true,backgroundColor:'rgb(60,32140)”,

自定义按钮类 从“React”导入React,{Component}; 从“react native”导入{平台、样式表、文本、视图、按钮、TouchableOpacity}

导出默认类FlatButton扩展组件{ 陈述={ 背景颜色:“#f01d71”, 背景色2:“#f01d71”, 答:错,, })

changeColor(){ 如果(!this.state.pressed){ setState({pressed:true,backgroundColor:'rgb(60,32140)”,backgroundColor2:'#f01d71'}); }否则{ this.setState({pressed:false,backgroundColor:'#f01d71',backgroundColor2:'#f01d71'}); } } render(){ 返回(
还可以使用立面属性

        <View style={{

            justifyContent: 'center',
            alignItems: 'center',
            padding:5
            }}>
            <TouchableOpacity
            style={{
            backgroundColor:'#ff0000', 
            borderRadius: 10,
            padding: 10,
            shadowColor: '#000000',
            shadowOffset: {
            width: 0,
            height: 3
            },
            shadowRadius: 10,
            shadowOpacity: 1.0,
            elevation: 5,
            }}>
              <Text style={styles.buttonText}>{"new button"}</Text>
            </TouchableOpacity>
          </View>

{“新建按钮”}

您必须传递属性:

backgroundColor: 'some color here'
如果不通过,阴影将无法正常工作

在TouchableOpacity样式上尝试以下操作:

style={{
    backgroundColor: this.state.backgroundColor || '#fff', 
    borderRadius: 10,
    padding: 10,
    shadowColor: '#000000',
    shadowOffset: {
      width: 0,
      height: 3
    },
    shadowRadius: 5,
    shadowOpacity: 1.0
    }}
当您使用| |时,按钮的背景将始终为白色,以防您不传递参数this.state.backgroundColor,就像您在这里调用组件时所做的那样

 <FlatButton text="Crop" />

谢谢@Surender Kumar
backgroundColor: 'some color here'
style={{
    backgroundColor: this.state.backgroundColor || '#fff', 
    borderRadius: 10,
    padding: 10,
    shadowColor: '#000000',
    shadowOffset: {
      width: 0,
      height: 3
    },
    shadowRadius: 5,
    shadowOpacity: 1.0
    }}
 <FlatButton text="Crop" />