在React Native中,borderRadius起作用,但按钮的背景色保持为正方形.这是怎么回事?

JS

<TouchableHighlight
  style={styles.submit}
  onPress={() => this.submitSuggestion(this.props)}
  underlayColor='#fff'>
    <Text style={[this.getFontSize(),styles.submitText]}>Submit</Text>
</TouchableHighlight>

风格

...
submit:{
    marginRight:40,
    marginLeft:40,
    marginTop:10,
},
submitText:{
    paddingTop:20,
    paddingBottom:20,
    color:'#fff',
    textAlign:'center',
    backgroundColor:'#68a0cf',
    borderRadius: 10,
    borderWidth: 1,
    borderColor: '#fff'
},
...

enter image description here

推荐答案

try 将按钮样式移动到TouchableHighlight本身:

Styles:

submit: {
  marginRight: 40,
  marginLeft: 40,
  marginTop: 10,
  paddingTop: 20,
  paddingBottom: 20,
  backgroundColor: '#68a0cf',
  borderRadius: 10,
  borderWidth: 1,
  borderColor: '#fff',
},
submitText: {
  color: '#fff',
  textAlign: 'center',
}

Button (same):

<TouchableHighlight
  style={styles.submit}
  onPress={() => this.submitSuggestion(this.props)}
  underlayColor='#fff'>
    <Text style={[this.getFontSize(),styles.submitText]}>Submit</Text>
</TouchableHighlight>

enter image description here

React-native相关问答推荐

在react native expo中从SDK 49升级到51后,应用程序使用堆栈导航崩溃

使用NextJS映射从数组中提取用户角色

条件呈现Else语句不会将样式应用于我的组件

在第二次加载时仅将本机应用程序设置为状态

React本机组件未更新状态

哪个版本的@stripe/stripe-react-native 模块支持 react native 0.62.0 typscript 模板?

如何在react native 中从 axios 重定向并将数据传递给路由

react-native - 如何在过go 两个文件夹中导入组件?

是否可以在 React Native 中隐藏BugReporting extraData?

如何在react native中过滤对象数组?

react-native run-android 在设备上构建旧版本的代码

在 React Native App 中禁用屏幕捕获/ScreenShot

try 在 Android 上运行我的 React Native 应用程序时出错

如何将捕获的图像与 react-native-camera 一起使用

React Native 发送短信

如何使 react-native Picker 停留在新 Select 的选项?

使用 React Native 一次启动多个 Animated.timing

React native - 以编程方式判断是否启用了远程 JS 调试

为什么我收到警告:函数作为 React 子级无效?

使用行数react-native文本组件