ToastAndroid

2019-08-14 14:24 更新

它揭示了如何將本地 ToastAndroid 模塊作為一個(gè) JS 模塊。它有一個(gè)名為 showText 的函數(shù),其擁有的參數(shù)如下所示:

  1. 字符串消息:將文本傳遞給 toast 的字符串

  2. int 持續(xù)期:toast 的持續(xù)期??赡苁?span id="djp1rdb" class="Apple-converted-space"> ToastAndroid.SHORT  ToastAndroid.LONG

方法

static show(message: string, duration: number)

性質(zhì)

SHORT: MemberExpression

LONG: MemberExpression

示例

'use strict';

var React = require('react-native');
var {
  StyleSheet,
  Text,
  ToastAndroid,
  TouchableWithoutFeedback
} = React;

var UIExplorerBlock = require('UIExplorerBlock');
var UIExplorerPage = require('UIExplorerPage');

var ToastExample = React.createClass({

  statics: {
    title: 'Toast Example',
    description: 'Toast Example',
  },

  getInitialState: function() {    return {};
  },

  render: function() {    return (
      <UIExplorerPage title="ToastAndroid">
        <UIExplorerBlock title="Simple toast">
          <TouchableWithoutFeedback
            onPress={() =>
              ToastAndroid.show('This is a toast with short duration', ToastAndroid.SHORT)}>
            <Text style={styles.text}>Click me.</Text>
          </TouchableWithoutFeedback>
        </UIExplorerBlock>
        <UIExplorerBlock title="Toast with long duration">
          <TouchableWithoutFeedback
            onPress={() =>
              ToastAndroid.show('This is a toast with long duration', ToastAndroid.LONG)}>
            <Text style={styles.text}>Click me too.</Text>
          </TouchableWithoutFeedback>
        </UIExplorerBlock>
      </UIExplorerPage>
    );
  },
});

var styles = StyleSheet.create({
  text: {
    color: 'black',
  },
});

module.exports = ToastExample;


以上內(nèi)容是否對(duì)您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)