【问题标题】:Hide soft keyboard for specific TextField in Nativescript在 Nativescript 中隐藏特定 TextField 的软键盘
【发布时间】:2021-10-08 16:27:11
【问题描述】:

我的目标是拥有一个保持焦点的隐藏文本字段,以便它可以接收来自蓝牙条形码扫描仪的输入。到目前为止,我已经完成了这一点,但是软键盘总是显示,这对应用程序来说是一个巨大的破坏。我曾尝试使用dismissSoftInput(),但键盘会在它被关闭之前弹出一会儿。我需要永远不要出现。

现在,我的代码是

    @ViewChild("scannerInput") scannerInput: ElementRef;

    private _isRunning: boolean;

    constructor() {}

    ngOnInit(): void {
        // as long as _isRunning is true, keepFocus will continue to call itself to make sure the input is focused
        this._isRunning = true;
        this.keepFocus();
    }

    ngOnDestroy(): void {
        // when the component is destroyed, keepFocus will stop running
        this._isRunning = false;
    }

    scanComplete($event) {
        var scan = <TextField>this.scannerInput.nativeElement;

        // Value of the barcode is evaluated here

        scan.text = "";
    }

    keepFocus() {
        setTimeout(() => {
            // the input will receive focus every half second
            var scan = <TextField>this.scannerInput.nativeElement;
            scan.focus();

            if(this._isRunning)
                this.keepFocus();
        }, 500)
    }

我的 HTML 是

<StackLayout class="layout-container">
    <TextField #scannerInput 
        name="scannerInput"
        id="scannerInput"
        (returnPress)="scanComplete($event)">
    </TextField>
</StackLayout>

我四处寻找答案,但似乎没有一个适合我的用例。我找到了一些解决方案,可以为整个应用程序/活动禁用软键盘,但是我需要在应用程序的其他部分使用键盘。

【问题讨论】:

    标签: nativescript angular2-nativescript


    【解决方案1】:

    我要使用的物理扫描仪设备今天下午终于到货了,所以我能够在真机而不是模拟器上对其进行测试。

    谢天谢地,蓝牙扫描仪似乎默认禁用键盘;所以问题“解决了”。

    如果有人有软件解决方案,我将暂时保留这个问题。

    【讨论】:

      猜你喜欢
      • 2020-09-17
      • 2016-11-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多