0

我正在通过 TouchableOpacity 设计自定义按钮以响应本机。到目前为止,我已经尝试了不同的样式方法,但没有得到所需的设计。下面提到的是我试图解决的问题。

<TouchableOpacity style={styles.numericButton}>
      <View>
          <Text style={styles.numericButtonText}>1</Text>
      </View>
</TouchableOpacity>


const styles = StyleSheet.create({

    numericButton: {
        margin:10,
        padding:10,
        backgroundColor:'#D3D3D3',
        borderColor:'#000',
        borderWidth:2,
        borderRadius:5,
        elevation:10,
        shadowOffset: { width: 5, height: 5 },
        shadowColor: "black",
        shadowOpacity: 1,
        shadowRadius: 5,

    },
    numericButtonText:{
        fontSize:24,
        fontWeight:'bold',
        fontFamily:'Cochin'
    }
});

结果:

输出图像

我想像这样设置我的反应原生按钮

在此处输入图像描述

4

2 回答 2

0

使用以下样式并使用更多渐变来设置与设计匹配的颜色并检查反映的变化

numericButton: {
  alignItems: 'center',
  margin: 10,
  padding: 10,
  backgroundColor: '#D3D3D3',
  borderColor: '#000',
  borderWidth: 2,
  //borderRadius:5,
  elevation: 5,
  shadowOffset: { width: 5, height: 5 },
  shadowColor: 'grey',
  shadowOpacity: 1,
  shadowRadius: 5,
},
numericButtonText: {
  fontSize: 24,
  fontWeight: 'bold',
  fontFamily: 'Cochin',
},

你可以走了!

于 2019-02-07T11:47:56.127 回答
0

我们可以使用react-native-linear-gradient实现相同类型的按钮

在此处输入图像描述

通过以下方式实现:

            <TouchableOpacity>
                <LinearGradient
                    // start={{x: 0.5, y: .5}} end={{x: 1, y: 1.0}}
                    style={styles.button}
                    locations={[0.3, 0, 0]}
                    colors={['#A8AFB5', 'white', 'white']}
                >
                     <Text style={styles.buttonText}>{props.data}</Text>
                </LinearGradient>
            </TouchableOpacity>




 const styles = StyleSheet.create({

    button: { flex: 1, flexDirection: 'row', justifyContent: 'center', alignItems: 'center', borderRadius: 5, width: null, height: 81,marginTop:5, borderWidth: 1 },
    buttonText: {
        //textAlign:'center',
        fontSize: 24,
        fontWeight: 'bold',
        fontFamily: 'Cochin',
        color: 'black'
    }
});
于 2019-02-11T09:25:44.080 回答