mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-16 03:31:45 +08:00
Merge pull request #3757 from NativeScript/fix-android-keyboard
FIX: Android keyboard
This commit is contained in:
@ -1,3 +1,6 @@
|
|||||||
|
import { ad } from "utils//utils";
|
||||||
|
import { isAndroid } from "platform";
|
||||||
|
|
||||||
export function onButtonLoaded(args) {
|
export function onButtonLoaded(args) {
|
||||||
if (args.object.android) {
|
if (args.object.android) {
|
||||||
args.object.android.setFocusableInTouchMode(true);
|
args.object.android.setFocusableInTouchMode(true);
|
||||||
@ -9,3 +12,9 @@ export function onButtonLoaded(args){
|
|||||||
export function onListViewLoaded(args) {
|
export function onListViewLoaded(args) {
|
||||||
args.object.items = [1];
|
args.object.items = [1];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function hideKeyboard() {
|
||||||
|
if (isAndroid) {
|
||||||
|
ad.dismissSoftInput();
|
||||||
|
}
|
||||||
|
}
|
@ -1,6 +1,7 @@
|
|||||||
<Page xmlns="http://schemas.nativescript.org/tns.xsd">
|
<Page xmlns="http://schemas.nativescript.org/tns.xsd">
|
||||||
<StackLayout>
|
<StackLayout>
|
||||||
<Button height="100" width="100" loaded="onButtonLoaded" text="Click me 3rd (Android)" style.fontSize="8"/>
|
<Button height="50" width="100" text="hide keyboard" onTap="hideKeyboard" style.fontSize="8"/>
|
||||||
|
<Button height="50" width="100" loaded="onButtonLoaded" text="Click me 3rd (Android)" style.fontSize="8"/>
|
||||||
<ListView loaded="onListViewLoaded">
|
<ListView loaded="onListViewLoaded">
|
||||||
<ListView.itemTemplate>
|
<ListView.itemTemplate>
|
||||||
<StackLayout>
|
<StackLayout>
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
export * from "./utils-common";
|
export * from "./utils-common";
|
||||||
|
|
||||||
import { getNativeApplication } from "application";
|
import { getNativeApplication, android as androidApp } from "application";
|
||||||
|
|
||||||
export module layout {
|
export module layout {
|
||||||
let density: number;
|
let density: number;
|
||||||
@ -98,10 +98,19 @@ export module ad {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function dismissSoftInput(nativeView: android.view.View): void {
|
export function dismissSoftInput(nativeView?: android.view.View): void {
|
||||||
const inputManager = getInputMethodManager();
|
const inputManager = getInputMethodManager();
|
||||||
if (inputManager && nativeView instanceof android.view.View && inputManager.isActive(nativeView)) {
|
let windowToken: android.os.IIBinder;
|
||||||
inputManager.hideSoftInputFromWindow(nativeView.getWindowToken(), 0);
|
|
||||||
|
if (nativeView instanceof android.view.View) {
|
||||||
|
windowToken = nativeView.getWindowToken()
|
||||||
|
} else if (androidApp.foregroundActivity instanceof android.app.Activity) {
|
||||||
|
const decorView = androidApp.foregroundActivity.getWindow().getDecorView();
|
||||||
|
windowToken = decorView ? decorView.getWindowToken() : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (inputManager && windowToken) {
|
||||||
|
inputManager.hideSoftInputFromWindow(windowToken, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
2
tns-core-modules/utils/utils.d.ts
vendored
2
tns-core-modules/utils/utils.d.ts
vendored
@ -94,7 +94,7 @@ export module ad {
|
|||||||
/**
|
/**
|
||||||
* Hides the soft input method, ususally a soft keyboard.
|
* Hides the soft input method, ususally a soft keyboard.
|
||||||
*/
|
*/
|
||||||
export function dismissSoftInput(nativeView: any /* android.view.View */): void;
|
export function dismissSoftInput(nativeView?: any /* android.view.View */): void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Shows the soft input method, ususally a soft keyboard.
|
* Shows the soft input method, ususally a soft keyboard.
|
||||||
|
Reference in New Issue
Block a user