如何解决react-native-elements Button默认有圆角无法显示标准矩形的问题
解决方案
react-native-elements 的 Button 组件默认内置了圆角样式,直接在 buttonStyle 属性中添加 borderRadius: 0 即可覆盖默认样式,实现标准矩形效果。
修改后的代码如下:
<Button title="Next" onPress={() => { // Next 相关逻辑 }} buttonStyle={{ backgroundColor: "#000000", width: 'auto', borderRadius: 0 // 新增该属性覆盖默认圆角 }} />
如果需要全局所有 Button 组件默认都是矩形样式,无需逐个配置,可以通过组件库的主题全局配置实现:
- 首先在项目入口文件配置自定义主题:
import { ThemeProvider, createTheme } from '@rneui/themed'; const customTheme = createTheme({ components: { Button: { buttonStyle: { borderRadius: 0 } } } });
- 用自定义主题的
ThemeProvider包裹你的应用根组件即可全局生效。
内容的提问来源于stack exchange,提问作者Nathan Getachew
相关产品推荐
相关产品推荐

