【问题标题】:React Native - Button Styling IssuesReact Native - 按钮样式问题
【发布时间】:2020-11-19 15:00:03
【问题描述】:

我很困惑为什么我的按钮看起来不像默认的原生反应按钮,其方形形状跨越视口的最大宽度 - 我已经研究并从反应文档中了解到原生按钮在样式和道具方面非常有限,但我的似乎缺少默认样式 - 任何提示?我的按钮组件可以找到here

我尝试将 backgroundColor 添加到样式、颜色等,但没有任何变化

【问题讨论】:

    标签: reactjs react-native jsx styling react-props


    【解决方案1】:

    试试这个...根据您的需要进一步定制 在此之后你会喜欢 react-native 和风格 :)

    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",
      },
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-11
      • 1970-01-01
      • 1970-01-01
      • 2016-04-10
      • 1970-01-01
      相关资源
      最近更新 更多