How to show and hide soft keyboard in Android

How to show and hide soft keyboard in Android

2023年7月7日发(作者:)

phonegap: How to show and hide soft keyboard inAndroidCreate a class that handles the keyboard

import ap;import t;import ethodManager;import w;public class KeyBoard { private WebView mAppView; private DroidGap mGap; public KeyBoard(DroidGap gap, WebView view) { mAppView = view; mGap = gap; } public void showKeyBoard() { InputMethodManager mgr = (InputMethodManager)temService(_METHOD_SERVICE); // only will trigger it if no physical keyboard is open ftInput(mAppView, _IMPLICIT);

((InputMethodManager)temService(_METHOD_SERVICE)).showSoftInput(mAppView, 0);

}

public void hideKeyBoard() { InputMethodManager mgr = (InputMethodManager)temService(_METHOD_SERVICE); ftInputFromWindow(dowToken(), 0); }}In your main activity add a Javascript interface for this class:

import ;import ap.*;public class Mobile_PG extends DroidGap { @Override public void onCreate(Bundle savedInstanceState) {

te(savedInstanceState); KeyBoard keyboard = new KeyBoard(this, appView); ascriptInterface(keyboard, "KeyBoard"); l("file:///android_asset/www/"); }}

From the javascript you now can call yBoard(); to show the soft keyboard and if needed you can hideit with yBoard();

I copy the android_ file into my and then ant compile and ant install. This is how the looks like:

Converting compiled files and external libraries into ${}... Running zip align on Installing ${e} onto default emulator Creating output directories Generating / from Compiling aidl files into Packaging resources Debug Package: ${e} No and properties found in ties. Please sign ${e} manually and run zipalign from the Android SDK tools. Signing Release Package: ${e} Unable to run 'ant uninstall', e property is not defined. Uninstalling ${e} from the default emulator Instrumenting classes from ${}/ Android Ant Build. Available targets: help: Displays this help. clean: Removes output files created by other targets. compile: Compiles project's .java files into .class files. debug: Builds the application and signs it with a debug key. release: Builds the application. The generated apk file must be signed before it is published. install: Installs/reinstalls the debug package onto a running emulator or device. If the application was previously installed, the signatures must match. uninstall: Uninstalls the application from a running emulator or device.

发布者:admin,转转请注明出处:http://www.yc00.com/web/1688678325a161809.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信