如何在单击文本框时隐藏IONIC 2中的原生android键盘? [英] How to hide native android keyboard in IONIC 2 when clicking on a text box?

查看:191
本文介绍了如何在单击文本框时隐藏IONIC 2中的原生android键盘?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用IONIC 2单击文本框时隐藏原生Android键盘?我从 https://ionicframework.com/docs/native/keyboard/ link并使用this.keyboard.close();
但是键盘仍在打开。帮我看看如何关闭键盘。我基本上是在TEXTBOX中的datepicker插件中显示DOB
在此处输入图像说明

How to hide native android keyboard when clicking on text box using IONIC 2? I have installed IONIC keyboard plugin from https://ionicframework.com/docs/native/keyboard/ link and uses this.keyboard.close(); But still keyboard is opening. Help me how to close the keyboard. I am basically showing DOB from the datepicker plugin in a TEXTBOXenter image description here.

这是ts文件(datepicker1.ts)

import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
    import { DatePicker } from '@ionic-native/date-picker';
    import { Keyboard } from '@ionic-native/keyboard';
    @IonicPage()
@Component({
  selector: 'page-datepicker1',
  templateUrl: 'datepicker1.html',
})
export class Datepicker1Page {
  public today:any;
  constructor(public navCtrl: NavController, public navParams: NavParams,private datePicker: DatePicker,private keyboard: Keyboard) {
  }

  ionViewDidLoad() {
    console.log('ionViewDidLoad Datepicker1Page');
  }
  openDatepicker()
  {

    this.keyboard.close();
    this.datePicker.show({
      date: new Date(),
      mode: 'date',
      androidTheme: this.datePicker.ANDROID_THEMES.THEME_DEVICE_DEFAULT_LIGHT
    }).then(
      date => {
        this.today=date.getDate()+'/'+date.getMonth()+'/'+date.getFullYear()},
      err => console.log('Error occurred while getting date: ', err)
    );
  }

}

这就是datepicker1.html页面

<ion-header>
  <ion-navbar>
    <ion-title>datepicker page</ion-title>
  </ion-navbar>
</ion-header>
<ion-content padding>
    <ion-item>
        <ion-label>DOB</ion-label>
        <ion-input type="text" name="DOB" (click)="openDatepicker()" [(ngModel)]="today" ng-readonly></ion-input>
      </ion-item>
</ion-content>


推荐答案

您错过了宣布今天类中的变量,你错过了在 ion-input disabled =true $ c>标签。一切正常,我已经测试过了。

You have missed to declare the today variable in the class and you missed to add disabled="true" in ion-input tag. Everything is working fine and I have tested it.

TS文件

import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { Keyboard } from '@ionic-native/keyboard';
import { DatePicker } from '@ionic-native/date-picker';

@Component({
  selector: 'page-home',
  templateUrl: 'home.html'
})
export class HomePage {

  constructor(public navCtrl: NavController, public keyboard : Keyboard, public datePicker : DatePicker) {

  }

  today : any;
  openDatepicker(){
    this.keyboard.close();
    this.datePicker.show({
      date: new Date(),
      mode: 'date',
      androidTheme: this.datePicker.ANDROID_THEMES.THEME_DEVICE_DEFAULT_LIGHT
    }).then(
      date => {
        this.today=date.getDate()+'/'+date.getMonth()+'/'+date.getFullYear()},
      err => console.log('Error occurred while getting date: ', err)
    );
  }

}

HTML文件

<ion-header>
  <ion-navbar>
    <ion-title>
      Ionic Blank
    </ion-title>
  </ion-navbar>
</ion-header>

<ion-content padding>
  <ion-item>
      <ion-label>DOB</ion-label>
      <ion-input disabled="true" type="text" name="DOB" (click)="openDatepicker()" [(ngModel)]="today" ng-readonly></ion-input>
    </ion-item>
</ion-content>

这篇关于如何在单击文本框时隐藏IONIC 2中的原生android键盘?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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