Nativescript 6.0 如何在 Android 中获取 Searchbar 的 focuschangeListener
Nativescript 6.0 How to get the focuschangeListener for Searchbar in Android
我在 Nativescript 中实现项目 angular。在 nativescript 5.0 中,我使用以下代码获得焦点更改侦听器。更新 6.0 后,我遇到 android.
中的问题
原因:搜索栏扩展了 androidx 小部件,任何人都可以帮助解决 6.0 中的问题。
<SearchBar id="searchBarMall"
[hint]="searchMall" (loaded)="searchBarloaded($event)"
(textChange)="onTextChanged($event)" (clear)="onClear($event)"
(submit)="onSubmit($event)"
textFieldHintColor="gray"></SearchBar>
打字稿
import { SearchBar } from "tns-core-modules/ui/search-bar";
import { Component, OnInit } from "@angular/core";
import { Page, isAndroid } from "tns-core-modules/ui/page";
@Component({
selector: "Home",
moduleId: module.id,
templateUrl: "./home.component.html",
styleUrls: ["./home.component.css"]
})
export class HomeComponent implements OnInit {
searchPhrase: string;
private searchbar: any;
onSearchSubmit(args): void {
let searchBar = <SearchBar>args.object;
console.log("You are searching for " + searchBar.text);
}
constructor(private _page: Page) {
}
ngOnInit(): void {
}
searchBarloaded(args) {
if (isAndroid) {
let self = this;
let searchBar = <SearchBar>args.object;
searchBar.android.setOnQueryTextFocusChangeListener(new android.view.View.OnFocusChangeListener({
onFocusChange: function (v: any, hasFocus: boolean) {
console.log("Focus" + hasFocus);
}
}));
this.searchbar.android.setFocusable(false);
this.searchbar.android.clearFocus();
}
}
ngAfterViewInit() {
this.searchbar = <SearchBar>this._page.getViewById("searchBarMall");
}
}
在 nativeView 上使用 setOnQueryTextFocusChangeListener。
this.searchbar.android.setOnQueryTextFocusChangeListener(new android.view.View.OnFocusChangeListener({
onFocusChange:function(v : any , hasFocus:boolean){
if(hasFocus){
...
}else{
...
}
}
}));
我在 Nativescript 中实现项目 angular。在 nativescript 5.0 中,我使用以下代码获得焦点更改侦听器。更新 6.0 后,我遇到 android.
中的问题原因:搜索栏扩展了 androidx 小部件,任何人都可以帮助解决 6.0 中的问题。
<SearchBar id="searchBarMall"
[hint]="searchMall" (loaded)="searchBarloaded($event)"
(textChange)="onTextChanged($event)" (clear)="onClear($event)"
(submit)="onSubmit($event)"
textFieldHintColor="gray"></SearchBar>
打字稿
import { SearchBar } from "tns-core-modules/ui/search-bar";
import { Component, OnInit } from "@angular/core";
import { Page, isAndroid } from "tns-core-modules/ui/page";
@Component({
selector: "Home",
moduleId: module.id,
templateUrl: "./home.component.html",
styleUrls: ["./home.component.css"]
})
export class HomeComponent implements OnInit {
searchPhrase: string;
private searchbar: any;
onSearchSubmit(args): void {
let searchBar = <SearchBar>args.object;
console.log("You are searching for " + searchBar.text);
}
constructor(private _page: Page) {
}
ngOnInit(): void {
}
searchBarloaded(args) {
if (isAndroid) {
let self = this;
let searchBar = <SearchBar>args.object;
searchBar.android.setOnQueryTextFocusChangeListener(new android.view.View.OnFocusChangeListener({
onFocusChange: function (v: any, hasFocus: boolean) {
console.log("Focus" + hasFocus);
}
}));
this.searchbar.android.setFocusable(false);
this.searchbar.android.clearFocus();
}
}
ngAfterViewInit() {
this.searchbar = <SearchBar>this._page.getViewById("searchBarMall");
}
}
在 nativeView 上使用 setOnQueryTextFocusChangeListener。
this.searchbar.android.setOnQueryTextFocusChangeListener(new android.view.View.OnFocusChangeListener({
onFocusChange:function(v : any , hasFocus:boolean){
if(hasFocus){
...
}else{
...
}
}
}));