sta*_*g91 5 javascript keyboard android cordova ionic-framework
我有以下问题,我需要完全禁用本机键盘.键盘只应在我调用show()时显示,并在我调用close()函数时隐藏(这将在用户切换键盘的Button上).单击Field和on Focus时显示的键盘需要完全禁用.
在Stackoverflow上我发现了这个:InputMethodManager im =(InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); im.hideSoftInputFromWindow(editText.getWindowToken(),0);
所以我的想法是在"Init"(IonicKeyboard.java中的第52行)我需要改变它.
if ("init".equals(action)) {
cordova.getThreadPool().execute(new Runnable() {
public void run() {
//new Logic on init
View v = cordova.getActivity().getCurrentFocus();
((InputMethodManager) cordova.getActivity().getSystemService(Context.INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(v.getWindowToken(), 0);
DisplayMetrics dm = new DisplayMetrics();
cordova.getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm);
final float density = dm.density;
//http://stackoverflow.com/a/4737265/1091751 detect if keyboard is showing
final View rootView = cordova.getActivity().getWindow().getDecorView().findViewById(android.R.id.content).getRootView();
OnGlobalLayoutListener list = new OnGlobalLayoutListener() {
int previousHeightDiff = 0;
@Override
public void onGlobalLayout() {
Rect r = new Rect();
//r will be populated with the coordinates of your view that area still visible.
rootView.getWindowVisibleDisplayFrame(r);
PluginResult result;
int heightDiff = rootView.getRootView().getHeight() - r.bottom;
int pixelHeightDiff = (int)(heightDiff / density);
if (pixelHeightDiff > 100 && pixelHeightDiff != previousHeightDiff) { // if more than 100 pixels, its probably a keyboard...
String msg = "S" + Integer.toString(pixelHeightDiff);
result = new PluginResult(PluginResult.Status.OK, msg);
result.setKeepCallback(true);
callbackContext.sendPluginResult(result);
}
else if ( pixelHeightDiff != previousHeightDiff && ( previousHeightDiff - pixelHeightDiff ) > 100 ){
String msg = "H";
result = new PluginResult(PluginResult.Status.OK, msg);
result.setKeepCallback(true);
callbackContext.sendPluginResult(result);
}
previousHeightDiff = pixelHeightDiff;
}
};
rootView.getViewTreeObserver().addOnGlobalLayoutListener(list);
PluginResult dataResult = new PluginResult(PluginResult.Status.OK);
dataResult.setKeepCallback(true);
callbackContext.sendPluginResult(dataResult);
}
});
return true;
}
return false; // Returning false results in a "MethodNotFound" error.
}
Run Code Online (Sandbox Code Playgroud)
可悲的是,这根本不起作用......
我想我也必须改变关闭/显示功能,但我不确定正确的代码是什么,我不知道这个改变是否会影响其他键盘行为.(但我基本上需要没有键盘的焦点)
我还发现了这个Cordova插件
看起来非常有前景,但我决定在Ionic Keyboard Plugin中更改它,因为我在Windows中也需要相同的行为.很高兴,如果有人能帮助我在这里.
关心克里斯托弗
这可以通过禁用所有输入并稍后使用Ionic Keyboard Pluginng-disabled显示键盘来实现。
如果您不希望输入在禁用时以不同的方式显示,您可以使用:disabled选择器通过 CSS 覆盖此样式。
<input ng-disabled="hideKeyboard">
Run Code Online (Sandbox Code Playgroud)
hideKeyboard = true;
Run Code Online (Sandbox Code Playgroud)
<input ng-disabled="hideKeyboard">
Run Code Online (Sandbox Code Playgroud)
function showKeyboard(){
hideKeyboard = false;
cordova.plugins.Keyboard.show();
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
895 次 |
| 最近记录: |