Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nativescript Android - hide keyboard

Tags:

nativescript

In my Nativescript app, the application starts with the login page. On iOS everything looks good, but on android, the username field is focused and the keyboard is showing. Is there a way to prevent this from happening?

So far I have tried:

  • Getting a reference of another element (a label) and calling lbl.focus() in the page's onLoaded event
  • getting a reference of the username textfield and calling txt.dismissSoftInput() and txt.android.clearFocus()

None of this worked. Is there another way to hide the keyboard when the page is loaded?

Thank you

like image 787
dpdragnev Avatar asked May 02 '26 04:05

dpdragnev


2 Answers

You want to clear the focus of the field in the loaded callback:

var searchBar = page.getViewById('my-search-bar-id');
if (searchBar.android) {
    searchBar.android.clearFocus();
}
like image 152
Emil Oberg Avatar answered May 04 '26 17:05

Emil Oberg


I guess the username field is either textview or textfield. If so, try this on loaded callback:

var myTextview = page.getViewById("myTextView");
myTextView.dismissSoftInput();
like image 30
Dean Le Avatar answered May 04 '26 18:05

Dean Le