触摸文本框外后如何隐藏键盘? [英] How to hide keyboard after touch outside the textfield?

查看:81
本文介绍了触摸文本框外后如何隐藏键盘?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个跨平台的应用程序.我有一个具有多个TextField的表单.当用户触摸文本框之外时,我想隐藏键盘,因为它覆盖了发送数据的按钮.

我该怎么办?

在我的.html文件中,我有:

<ScrollView>
  <GridLayout ios:style="margin-top:50">
    <StackLayout class="form">

      <!-- Some TextView -->

    </StackLayout>
  </GridLayout>
</ScrollView>

编辑

这是显示错误的游乐场. /p>

解决方案

在布局中添加一个tap侦听器,并使用

隐藏键盘

iOS

import * as utils from "tns-core-modules/utils/utils";

UIApplication.sharedApplication
        .keyWindow
        .endEditing(true);

Android

utils.ad.dismissSoftInput();

修改

如果Page中只有一个TextField,则可以只在TextField上调用dismissSoftInput()方法.如果您在Page上有多个TextField,并且不确定实际上是哪个焦点,那么上面的代码会有所帮助.

游乐场样品

I have a cross-platform app. I have a form that has more than one TextField. I want to hide the keyboard when the user touch outside of the textfield because it covers the button that sends the data.

How can I do?

In my .html file I have:

<ScrollView>
  <GridLayout ios:style="margin-top:50">
    <StackLayout class="form">

      <!-- Some TextView -->

    </StackLayout>
  </GridLayout>
</ScrollView>

EDIT

This is a Playground that show the error.

解决方案

Add a tap listener to your layout and hide keyboard using

iOS

import * as utils from "tns-core-modules/utils/utils";

UIApplication.sharedApplication
        .keyWindow
        .endEditing(true);

Android

utils.ad.dismissSoftInput();

Edit

You may simply call dismissSoftInput() method on the TextField if it's just one TextField in your Page. The above code helps if you have multiple TextFields on your Page and not sure which one is actually focused.

Playground Sample

这篇关于触摸文本框外后如何隐藏键盘?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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