Javascript 将本机边界半径与背景色进行反应
在React Native中,Javascript 将本机边界半径与背景色进行反应,javascript,styles,react-native,Javascript,Styles,React Native,在React Native中,borderRadius正在工作,但按钮的背景色保持为正方形。这是怎么回事 JS 尝试将按钮样式移动到可触摸突出显示按钮本身: 样式: submit: { marginRight: 40, marginLeft: 40, marginTop: 10, paddingTop: 20, paddingBottom: 20, backgroundColor: '#68a0cf', borderRadius: 10, borderWidth:
borderRadius
正在工作,但按钮的背景色保持为正方形。这是怎么回事
JS
尝试将按钮样式移动到
可触摸突出显示按钮本身:
样式:
submit: {
marginRight: 40,
marginLeft: 40,
marginTop: 10,
paddingTop: 20,
paddingBottom: 20,
backgroundColor: '#68a0cf',
borderRadius: 10,
borderWidth: 1,
borderColor: '#fff',
},
submitText: {
color: '#fff',
textAlign: 'center',
}
<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,
paddingTop: 20,
paddingBottom: 20,
backgroundColor: '#68a0cf',
borderRadius: 10,
borderWidth: 1,
borderColor: '#fff',
},
submitText: {
color: '#fff',
textAlign: 'center',
}
<TouchableHighlight
style={styles.submit}
onPress={() => this.submitSuggestion(this.props)}
underlayColor='#fff'>
<Text style={[this.getFontSize(),styles.submitText]}>Submit</Text>
</TouchableHighlight>
this.submitSuggestion(this.props)}
参考底色='#fff'>
提交
您应该将溢出:隐藏
添加到您的样式中:
Js:
应用以下代码行:
<TextInput
style={{ height: 40, width: "95%", borderColor: 'gray', borderWidth: 2, borderRadius: 20, marginBottom: 20, fontSize: 18, backgroundColor: '#68a0cf' }}
// Adding hint in TextInput using Placeholder option.
placeholder=" Enter Your First Name"
// Making the Under line Transparent.
underlineColorAndroid="transparent"
/>
永远不要给你的
加上边界半径,一定要把
包在你的
或
里
上的borderRadius将在Android设备上完美运行。但在IOS设备上它无法工作。
因此,在您的实践中,将您的
包装在
内或
上,然后为该
或
提供边界半径,以便它可以在Android和IOS设备上工作
例如:-
<TouchableOpacity style={{borderRadius: 15}}>
<Text>Button Text</Text>
</TouchableOpacity>
按钮文本
-谢谢记住
如果你想给文本一个背景色,然后再给它一个边框半径在这种情况下也写溢出:'隐藏'你的文本有一个背景色也会得到半径,否则它是不可能实现的,除非你包装它与视图,并给它背景色和半径
<Text style={{ backgroundColor: 'black', color:'white', borderRadius:10, overflow:'hidden'}}>Dummy</Text>
Dummy
只是一个猜测,试着给submitText提供边框样式:'solid'
,不,这在您测试的环境中不起作用?ios还是android?谢谢!padding
也是另一个重要的键。overflow:“hidden”
即使没有react native buttonThanks,对我来说也很有效。是的,将backgroundColor
和borderRadius
放在容器上,然后将overflow:“hidden”
添加到容器中对我来说很有效。(也不要使用react native按钮
)这就是我想要的!(不是选中的那个)
<TouchableOpacity style={{borderRadius: 15}}>
<Text>Button Text</Text>
</TouchableOpacity>
<Text style={{ backgroundColor: 'black', color:'white', borderRadius:10, overflow:'hidden'}}>Dummy</Text>