spl*_*unk 10 reactjs react-native
我正在使用react-native,我已经创建了一个Alert元素.
Alert.alert(
'Warning',
'bla bla bla',
[
{text: 'OK', onPress: () => console.log('OK Pressed')},
]
)
Run Code Online (Sandbox Code Playgroud)
现在我想对它应用一些风格.假设我想将红色背景颜色和白色应用于文本.
我怎样才能做到这一点?可能吗?
您可以使用自定义库,例如react-native-modalbox。
您将可以根据需要设置样式的样式:
<Modal style={{background: 'red'}} ref={"modal1"}>
<Text style={{color: 'white'}}>Basic modal</Text>
<Button onPress={this.toggleSwipeToClose} style={styles.btn}>Disable swipeToClose({this.state.swipeToClose ? "true" : "false"})</Button>
</Modal>
Run Code Online (Sandbox Code Playgroud)
您可以使用以下方式打开模式
openModal1(id) {
this.refs.modal1.open();
}
Run Code Online (Sandbox Code Playgroud)
查看示例以查看更多选项。
奖励:如果您想为react-native找到一个好的库,请尝试js.coach
实际上有一种方法可以自定义按钮上的文本,但是您只能使用提供的内容...以下是来自react native的类型定义.然后是一个显示红色按钮的简单示例.基本上"默认"是蓝色,"取消"是粗体但仍然是蓝色,"破坏性"是红色.
**
* An Alert button style
*/
export type AlertButtonStyle = $Enum<{
/**
* Default button style
*/
'default': string,
/**
* Cancel button style
*/
'cancel': string,
/**
* Destructive button style
*/
'destructive': string,
}>;
Alert.alert("Look out!",
"Hitting reset will wipe all the app's data on your phone. This cannot be undone!",
[
{text: 'Reset', onPress: this._doSomethingSerious, style: 'destructive'},
{text: 'Cancel'},
],
{cancelable: false}
)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
27532 次 |
| 最近记录: |