React Native Android

本文分享了作者首次使用React Native进行Android应用开发的经历,包括显示图片和弹出提示的基础操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<span style="font-family: Arial, Helvetica, sans-serif;">/**</span>
 * Sample React Native App
 * https://github.com/facebook/react-native
 * @flow
 */

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


var MOCKED_MOVIES_DATA = [
  {title: 'Title', year: '2015', posters: {thumbnail: 'http://img1.cache.netease.com/ent/2015/8/4/20150804081025eb75c.jpg'}},
];

class SampleApp extends Component {
  render() {
    var movie = MOCKED_MOVIES_DATA[0];
    return (
      <View style={styles.container}>
        <Text style={styles.welcome}>
          {movie.title+movie.year}
        </Text>
        <Text style={styles.instructions}>
          To get started, edit index.android.js
        </Text>

            <Text style={styles.instructions} onPress={onClick}>
                Shake or press menu button for dev menu
            </Text>
            <Image
                source={{uri: movie.posters.thumbnail}}
                style = {styles.imagestyle}
            />

      </View>
    );
  }
}

function onClick(){
   var ToastAndroid = require('ToastAndroid')
   ToastAndroid.show('Awesome, Clicking!', ToastAndroid.SHORT);
   console.log('pressed')
}
const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',//
    alignItems: 'center',
    backgroundColor: '#F5FCFF',
  },
  btn:{
        width:50,
        backgroundColor:'#0091FF',
        justifyContent:'center',
        alignItems:'center'
      },
  welcome: {
    fontSize: 20,
    textAlign: 'center',
    margin: 10,
  },
  instructions: {
    textAlign: 'center',
    color: '#333333',
    marginBottom: 5,
  },
  style_view_button:{
      marginTop:15,
      marginLeft:10,
      marginRight:10,
      backgroundColor:'#63B8FF',
      borderColor:'#5bc0de',
      height:45,
      width:50,
      borderRadius:5,
      justifyContent: 'center',
      alignItems: 'center',
  },
  imagestyle: {
    width: 100,
    height:100,
  },
});

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


rn 的android 教程我找了很久也没找到全面/细致 一些的教程,真是苦恼,摸着石头过河真的很辛苦。可能还没兴起,所以教程比较少,不过这就是我的乐趣所在。

ps:虽然做了将近2年android,但是因为一点js基础都没有,做rn 太吃力,今天实现了显示image 和 toast,乐的不行。。。。。。。。。





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值