本机基本无线电颜色不起作用?

时间:2018-06-20 06:13:39

标签: react-native-android native-base

我需要为“单选”按钮设置自定义颜色,这就是我很累的地方:

<Radio
       color={"#ff0000"}
       selectedColor={"#ff0000"}
       selected={true}
       onPress={ ()=> this.props.somefunc() }
 />

4 个答案:

答案 0 :(得分:3)

我发现它可以正常工作。试试这个代码。

import React, { Component } from 'react';
import { Container, Header, Content, ListItem, Text, Radio, Right } from 'native-base';
export default class App extends Component {

  state = {
    radioBtnOne: false,
    radioBtnTwo: false
  }

  render() {
    return (
      <Container>
        <Header />
        <Content>
          <ListItem onPress={() => this.setState({ radioBtnOne: !this.state.radioBtnOne })}>
            <Text>Daily Stand Up</Text>
            <Right>
              <Radio selected={this.state.radioBtnOne} color="red" selectedColor="green" onPress={() => this.setState({ radioBtnOne: !this.state.radioBtnOne })} />
            </Right>
          </ListItem>
          <ListItem onPress={() => this.setState({ radioBtnTwo: !this.state.radioBtnTwo })}>
            <Text>Discussion with Client</Text>
            <Right>
              <Radio selected={this.state.radioBtnTwo} color="red" selectedColor="green" onPress={() => this.setState({ radioBtnOne: !this.state.radioBtnOne })} />
            </Right>
          </ListItem>
        </Content>
      </Container>
    );
  }
}

Gif

enter image description here

答案 1 :(得分:1)

新版本的本地基础(2.7.2)解决了该问题。

答案 2 :(得分:0)

同样的问题,这就是为什么我用 库:react-native-flexi-radio-button

您还使用以下库之一 1:react-native-simple-radio-button 2:单选按钮反应式原生

答案 3 :(得分:-1)

未选择单选按钮时:

 <Radio selected={false} color="gray" selectedColor="green" />

选择单选按钮时: