加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

React Native : 按钮 Button

发布时间:2020-12-15 08:25:33 所属栏目:百科 来源:网络整理
导读:React Native初探: http://www.jb51.cc/article/p-wtukbzxm-bob.html RN内置了 Touchable* 可用来生成按钮。例如: TouchableHighlight onPress={this._onPressButton} TextButton1/Text /TouchableHighlight 就差自定义样式了。 1、react-native-button库

React Native初探: http://www.52php.cn/article/p-wtukbzxm-bob.html

RN内置了Touchable*可用来生成按钮。例如:

<TouchableHighlight onPress={this._onPressButton}>
          <Text>Button1</Text>
        </TouchableHighlight>

就差自定义样式了。

1、react-native-button库

https://github.com/ide/react-native-button 里做了简单的封装。

npm install react-native-button --save

代码示例:

import React,{ Component } from 'react';
import {
  AppRegistry,StyleSheet,Text,View,TouchableHighlight
} from 'react-native';

import Button from 'react-native-button';

class MyReactNativeProject extends Component {

  _onPressButton() {
    console.log("You tapped the button!");
  }

  _onPressButton2() {
    console.log('Pressed!');
  }
  render() {

    return (
      <View style={styles.container}>

        <TouchableHighlight onPress={this._onPressButton}>
          <Text>Button1</Text>
        </TouchableHighlight>

        <Button
          style={{fontSize: 20,color: 'green'}}
          styleDisabled={{color: 'red'}}
          onPress={() => this._onPressButton2()}>
          Button2
        </Button>

      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,justifyContent: 'center',alignItems: 'center',backgroundColor: '#F5FCFF',},});

AppRegistry.registerComponent('MyReactNativeProject',() => MyReactNativeProject);

效果图:

2、react-native-awesome-button库

这个更像按钮。

https://github.com/larsvinter/react-native-awesome-button

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读