我对为什么我的按钮看起来不像默认的本机React按钮感到困惑,该按钮的方形形状跨越了视口的最大宽度-我已经研究并从react文档中了解到本机按钮按钮的样式和道具非常有限,但是我的按钮似乎缺少默认样式-有什么提示吗?我的按钮组件可以在here
中找到我尝试将backgroundColor添加到样式,颜色等中,但是没有任何变化
答案 0 :(得分:0)
尝试此操作...根据需要进一步自定义 您将喜欢本机的反应性,并喜欢这种风格的人:)
import React, { useState } from "react";
import { StyleSheet, View, TextInput, TouchableOpacity } from "react-native";
export default function AddTodo({ submitHandler }) {
const [text, setText] = useState("");
const changeHandler = (val) => {
setText(val);
};
return (
<View>
<TextInput
style={styles.input}
placeholder="add a game to the docket..."
placeholderTextColor="white"
onChangeText={changeHandler}
clearTextOnFocus="true"
/>
<TouchableOpacity style={styles.btn} onPress={() => submitHandler(text)}>
<Text style={styles.btnText}>add game</Text>
</TouchableOpacity>
</View>
);
}
const styles = StyleSheet.create({
input: {
marginBottom: 10,
paddingHorizontal: 8,
paddingVertical: 6,
backgroundColor: "#2DCCCF",
flexDirection: "row",
color: "white",
},
btn: {
height: 45,
borderRadius: 8,
elevation: 3,
backgroundColor: "#AB47BC",
justifyContent: "center",
},
btnText: {
color: "#fff",
},
});