react-native - 按钮样式在本机反应中不起作用
问题描述
我想更改按钮边框半径、颜色和填充,但它不起作用
这是我的看法
import * as React from 'react';
import { StatusBar } from 'expo-status-bar';
import { Button, StyleSheet, Text, View, Image} from 'react-native';
import {NavigationContainer} from '@react-navigation/native';
import {createStackNavigator} from '@react-navigation/stack';
function HomeScreen({navigation}) {
return(
<View
style={styles.container}>
<Text>Home Screen</Text>
<Button
style={styles.button}
title= "Go To Details"
onPress={()=> navigation.navigate('Details')}
/>
</View>
)
}
这是我的风格
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
button: {
width: 200,
marginTop: 20,
backgroundColor: "green",
padding: 15,
borderRadius: 50,
},
});
有什么我想念的吗?
解决方案
我不认为您可以使用 react native Button 进行自定义。但是您可以更改标题、颜色等内容。查看他们的文档https://reactnative.dev/docs/button
更好的方法是使用您的自定义样式制作您自己的按钮,如下所示:
<TouchableOpacity onPress={()=> navigation.navigate('Details')}>
<View style={styles.button}>
<Text>Go To Details</Text>
</View>
</TouchableOpacity>
推荐阅读
- javascript - 捕获自定义错误并发回自定义响应
- sql-server - 如何将字符串的每个元素取出到单独的列中?
- airflow - BaseSensorOperator 的 timeout 和 execution_timeout 参数之间的预期区别是什么?
- excel - VBA 记录读取限制?
- python - gdal 和 ThreadPoolExecutor——线程安全?
- javascript - 模块外的继承导入语句
- excel - 我需要一个宏,他从下面的许多不同宏中向我询问您需要运行哪个宏
- linux - 连接 ioctl 和驱动程序操作
- git - 如何在“git clone --depth=1”之后获取整个 git 历史记录?
- routes - 使用 strongswan 的连接问题