如何在本机反应中添加文本输入以发出警报 [英] How to add a text input to alert in react native

查看:33
本文介绍了如何在本机反应中添加文本输入以发出警报的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以帮助将文本输入添加到 React Native 中的警报吗?是否可以?我搜索并找到了处理多行文本输入的结果,而我的情况并非如此.提前致谢

Can someone help with adding a text input to an alert in react native. Is it possible? I searched and found results that deals with multiple line text input which is not the case with me. Thanks in advance

推荐答案

这是可能的.我相信这最初仅适用于 AlertIOS,但它似乎已集成到 React Native Alert.

This is possible. I believe this was only available initially for AlertIOS however it seems to have been intergrated to React Native Alert.

虽然它被添加到 Alert 中,但它似乎不适用于 Android

Although its added to Alert it does not seem to work for Android

使用

import { Alert } from 'react-native'; 

onButtonPress = () => {
    Alert.prompt(
      "Enter password",
      "Enter your password to claim your $1.5B in lottery winnings",
      [
        {
          text: "Cancel",
          onPress: () => console.log("Cancel Pressed"),
          style: "cancel"
        },
        {
          text: "OK",
          onPress: password => console.log("OK Pressed, password: " + password)
        }
      ],
      "secure-text"
    );
  };
}

更多详情:https://reactnative.dev/docs/alertios

这篇关于如何在本机反应中添加文本输入以发出警报的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆