4

react-native の TextInput のフォーカス スタイルと同様に、textInput のプロパティ underlineColorAndroid を変更しようとしています。

React-Native 0.28.0 を使用しています

OnFocus では、属性は変更されません。フォーカスの下線を別の色に変更するにはどうすればよいですか?

私のサンプルコードは以下の通りです:

'use strict';

import React, { Component } from 'react';

import {
  AppRegistry,
  StyleSheet,
  Text,
  View,
  TextInput,
  ScrollView
} from 'react-native';

class RNPlayground extends Component {
  constructor(props) {
    super(props);
    this.state = {
      hasFocus: false
    }
  }

  _onBlur() {
    this.setState({hasFocus: false});
    }

  _onFocus() {
    this.setState({hasFocus: true});
    }

  _getULColor(hasFocus) {
    console.error(hasFocus);
    return (hasFocus === true) ? 'pink' : 'violet';
  }

  render() {
    console.error("this.state=");
    console.error(this.state);
    console.error("this.state.hasFocus=");
    console.error(this.state.hasFocus);

    return (
      <View style={styles.container}>
        <ScrollView>
          <TextInput
            placeholder="textInput"
            onBlur={ () => this._onBlur() }
            onFocus={ () => this._onFocus() }
            style={styles.instructions}
            underlineColorAndroid={this._getULColor(this.state.hasFocus)}/>
                </ScrollView>
        <TextInput>Some sample text</TextInput>
      </View>
    );
  }
};

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#F5FCFF',
  },
  welcome: {
    fontSize: 28,
    textAlign: 'center',
    margin: 10,
  },
  instructions: {
    textAlign: 'center',
    color: '#333333',
    fontSize: 19,
    marginBottom: 5,
  }

});

AppRegistry.registerComponent('RNPlayground', () => RNPlayground);
4

1 に答える 1

0

さて、あなたのコードは正しく、正しく動作するはずです。 これが実際の例です

この回答に反対票を投じないでください。残念ながら、この例のように rnplay サービスはもう利用できません。または反対票を投じますが、あなたの主張を説明してください。

于 2016-07-06T10:23:47.407 に答える