Nativescript 6.0如何在Android中获取搜索栏的focuschangeListener

Nativescript 6.0如何在Android中获取搜索栏的focuschangeListener,nativescript,nativescript-angular,Nativescript,Nativescript Angular,我在Nativescript中实现该项目。在nativescript 5.0中,我使用以下代码获取焦点更改侦听器。更新6.0后,我在android中面临这个问题 原因:搜索栏扩展了androidx小部件,任何人都可以帮助解决6.0中的问题 <SearchBar id="searchBarMall" [hint]="searchMall" (loaded)="searchBarloaded($event)" (textChange)="onTextChange

我在Nativescript中实现该项目。在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");
    }
}
从“tns核心模块/ui/search bar”导入{SearchBar};
从“@angular/core”导入{Component,OnInit};
从“tns核心模块/ui/Page”导入{Page,isAndroid};
@组成部分({
选择器:“主页”,
moduleId:module.id,
templateUrl:“./home.component.html”,
样式URL:[“/home.component.css”]
})
导出类HomeComponent实现OnInit{
搜索短语:字符串;
私人搜索栏:任何;
onSearchSubmit(args):无效{
让searchBar=args.object;
log(“您正在搜索”+searchBar.text);
}
构造函数(专用页:第页){
}
ngOnInit():void{
}
searchBarloaded(args){
if(isAndroid){
让自我=这个;
让searchBar=args.object;
searchBar.android.setOnQueryTextFocusChangeListener(新的android.view.view.OnFocusChangeListener({
onFocusChange:function(v:any,hasFocus:boolean){
console.log(“焦点”+hasFocus);
}
}));
this.searchbar.android.setFocusable(false);
this.searchbar.android.clearFocus();
}
}
ngAfterViewInit(){
this.searchbar=this.\u page.getViewById(“searchBarMall”);
}
}
在nativeView上使用

this.searchbar.android.setOnQueryTextFocusChangeListener(new android.view.View.OnFocusChangeListener({
                onFocusChange:function(v : any , hasFocus:boolean){
                    if(hasFocus){
                       ...
                    }else{
                        ...
                    }
                }
            }));

请共享游乐场示例,这可能取决于您访问searchview的时间/方式。您好,Manoj I更新了游乐场代码,因为游乐场在新android中返回错误。视图…游乐场返回错误找不到名称“android”,游乐场链接在哪里,我找不到。我无法创建应用程序,因此我更新了问题中的代码