nativescript - 用于 Nativescript-Vue 的搜索栏的 DismissSoftInput()
问题描述
解释问题:
搜索栏无法关闭打开的键盘。这使得搜索栏非常不可用,因为正常的用户模式是用户搜索某些内容,然后按下该项目并在那里导航。在 Android 上(至少在 >= 5.x 上),打开的键盘将继续保持打开状态,即使在新页面上也是如此。
参考Github上的问题,任何人如何为 Nativescript-Vue 而不是为带有 Typescript 的 Nativescript 做到这一点
更新:
添加游乐场:https ://play.nativescript.org/?template=play-vue&id=hrrcW9
如果我最小化应用程序,然后再次单击它,键盘将再次弹出。
解决方案
正如您在链接问题中已经看到的那样,功能请求已完成关闭。现在, dismissSoftInput()是 SearchBar 上的一个方法,它隐藏了键盘。
如果您仍有问题,请分享您的代码。
更新:
将第一个可聚焦元素集中在片段/活动上是 Android 的默认行为。添加事件侦听器/超时以从每个屏幕移除焦点可能很烦人,我更喜欢使用自动焦点视图作为我的布局的第一个元素(这不会对屏幕设计产生任何影响),这将阻止自动聚焦于我的文本字段/搜索栏。
import { View } from "tns-core-modules/ui/core/view";
export class AutoFocusView extends View {
createNativeView() {
if (typeof android !== "undefined") {
const linearLayout = new android.widget.LinearLayout(this._context);
linearLayout.setFocusableInTouchMode(true);
linearLayout.setFocusable(true);
return linearLayout;
}
return super.createNativeView();
}
onLoaded() {
super.onLoaded();
if (typeof android !== 'undefined') {
this.requestFocus();
}
}
requestFocus() {
if (typeof android !== "undefined") {
const nativeViewProtected = this.nativeViewProtected;
nativeViewProtected.requestFocus();
}
}
}
推荐阅读
- oracle - 除了状态行,不显示 Oracle Forms 消息
- spring-amqp - ImmediateRequeueAmqpException 似乎不起作用
- c# - 如何使用声纳扫描仪扫描 C# 项目
- node.js - Button Component中的MUI奇怪代码,希望有人能解释一下
- f# - 4.5 版中的阴影
- python - 关于通过 ssh 将 opencv 库安装到树莓派 4 的问题
- php - CakePHP:Bin 蛋糕烘焙表不存在
- reactjs - 如何使用 gatsby 插件将 CSS 更改为 SASS?
- pdf - 如何使用 Apps 脚本访问 Google Drive 上受密码保护的 PDF 文件
- asp.net - 如何将 DataTables 脚本与已填充的表一起使用