当页面使用nativescript在android应用中加载页面时,如何显示键盘? [英] How to show keyboard when page loads in android app with nativescript?

查看:74
本文介绍了当页面使用nativescript在android应用中加载页面时,如何显示键盘?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的android应用程序的第一页有一个输入字段.所以我想要的是当此页面加载时,我想自动显示键盘而无需在输入字段上进行点击.

The first page of my android application has one input field. So what I want is when this page loads I want to show keyboard automatically without doing tap on the input field.

推荐答案

pkanev的评论在ios上为true;也就是说,只要专注于文本字段,ios就会打开键盘.

pkanev's comment is true on ios; ie, just focus on the text field and ios will open up the keyboard.

但是在Android上,您需要做一些额外的工作-

But on Android you need to do some extra work --

var utils = require("tns-core-modules/utils/utils");

var myTextfield = page.getViewById("myTextFieldId");

if (myTextfield.ios) {
    console.log("myTextfield.ios");

    // on ios this will open the keyboard but not on android
    myTextfield.focus();
}

if (myTextfield.android) {
    console.log("myTextfield.android");

    setTimeout(function() {

        // places the cursor here but doesn't open the keyboard
        myTextfield.android.requestFocus();

        var imm = utils.ad.getInputMethodManager();

        imm.showSoftInput(myTextfield.android, 0);

    }, 300);
}

请注意使用setTimeout,这也是您在本机Android中也需要做的事情.

Notice the use of setTimeout which is what you would need to do in native Android too.

这篇关于当页面使用nativescript在android应用中加载页面时,如何显示键盘?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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