我是个新来的本地人.在我的应用程序中,我使用一个switch 并改变 colored颜色 来区分switch ,但我的实际要求是在switch 内显示"是"或"否"文本,如下所示.

enter image description here

这是我的代码:

<Switch
                    onValueChange={this.change.bind(this)}
                    style={{marginBottom:10,width:90,marginRight:6,marginLeft:6}}
                    value={true}
                    thumbTintColor="#0000ff"
                    tintColor="#ff0000"
                    />

请给我一些建议来解决这个问题,非常感谢任何帮助.

推荐答案

最后我打开了内部switch .......

安装

npm 安装 --save react-native-switch

    import { Switch } from 'react-native-switch';

<Switch
value={true}
onValueChange={(val) => console.log(val)}
disabled={false}
activeText={'On'}
inActiveText={'Off'}
backgroundActive={'green'}
backgroundInactive={'gray'}
circleActiveColor={'#30a566'}
circleInActiveColor={'#000000'}/>

请参考此链接...

React-native相关问答推荐

出现错误:使用 process(css).then(cb) 来使用异步插件

React 从 babel 6 到 babel 7 的原生升级

什么时候适合在 React 中使用构造函数?

library not found for -lRCTGeolocation

在 react-native 元素中更改 android 和 ios 的入口文件路径

使用像 React Navigation 这样的基于 JS 的导航解决方案优缺点?

React Navigation TabNavigator:在选项卡更改时重置上一个选项卡

React native - 创建单例模式的最佳方式

在配置 react-native-maps 中获取 "supportLibVersion" 、 "playServicesVersion" 和 "androidMapsUtilsVersion" 值

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

如何在 Text 中围绕 Text 包裹 TouchableOpacity?

Animated.View 的样式props的Typescript定义

查找文本输入框和按钮字段的资源名称以响应本机 android 应用程序

Native Script 与 react native 和 ionic 框架的区别

react-native 元素/目录 struct 设置

React Native EXPO Apple 上传失败

React-Native 元素卡在 :app:installDebug

在 React Native 中,两个等宽的按钮水平填充屏幕

使用 TouchableWithoutFeedback react-native onPress 不起作用

React Navigation获取堆栈标题高度