貌似沒什麼用的軟體盤彈出的功能,利用pg怎麼去實現,純屬娛樂
1.首先是phonegap必備的兩個檔案,分別是本地.java代碼SoftKeyBoard.java
[java]
package com.tricedesigns;
import org.json.JSONArray;
import android.content.Context;
import android.view.inputmethod.InputMethodManager;
import com.phonegap.api.Plugin;
import com.phonegap.api.PluginResult;
public class SoftKeyBoard extends Plugin {
public SoftKeyBoard() {
}
public void showKeyBoard() {
InputMethodManager mgr = (InputMethodManager) ((Context) this.ctx).getSystemService(Context.INPUT_METHOD_SERVICE);
mgr.showSoftInput(webView, InputMethodManager.SHOW_IMPLICIT);
((InputMethodManager) ((Context) this.ctx).getSystemService(Context.INPUT_METHOD_SERVICE)).showSoftInput(webView, 0);
}
public void hideKeyBoard() {
InputMethodManager mgr = (InputMethodManager) ((Context) this.ctx).getSystemService(Context.INPUT_METHOD_SERVICE);
mgr.hideSoftInputFromWindow(webView.getWindowToken(), 0);
}
public boolean isKeyBoardShowing() {
int heightDiff = webView.getRootView().getHeight() - webView.getHeight();
return (100 < heightDiff); // if more than 100 pixels, its probably a keyboard...
}
public PluginResult execute(String action, JSONArray args, String callbackId) {
if (action.equals("show")) {
this.showKeyBoard();
return new PluginResult(PluginResult.Status.OK, "done");
}
else if (action.equals("hide")) {
this.hideKeyBoard();
return new PluginResult(PluginResult.Status.OK);
}
else if (action.equals("isShowing")) {
return new PluginResult(PluginResult.Status.OK, this.isKeyBoardShowing());
}
else {
return new PluginResult(PluginResult.Status.INVALID_ACTION);
}
}
}
2.(.js檔案share.js)其中的一個顯示方法
[javascript]
var SoftKeyBoard={
skbShow:function(win, fail){
return cordova.exec(
function (args) { if(win !== undefined) { win(args); } },
function (args) { if(fail !== undefined) { fail(args); } },
"SoftKeyBoard",
"show",
[]);
}
}
/*function SoftKeyBoard() {}
SoftKeyBoard.prototype.show = function(win, fail) {
return PhoneGap.exec(
function (args) { if(win !== undefined) { win(args); } },
function (args) { if(fail !== undefined) { fail(args); } },
"SoftKeyBoard",
"show",
[]);
};
SoftKeyBoard.prototype.hide = function(win, fail) {
return PhoneGap.exec(
function (args) { if(win !== undefined) { win(args); } },
function (args) { if(fail !== undefined) { fail(args); } },
"SoftKeyBoard",
"hide",
[]);
};
SoftKeyBoard.prototype.isShowing = function(win, fail) {
return PhoneGap.exec(
function (args) { if(win !== undefined) { win(args); } },
function (args) { if(fail !== undefined) { fail(args); } },
"SoftKeyBoard",
"isShowing",
[]);
};
PhoneGap.addConstructor(function() {
PhoneGap.addPlugin('SoftKeyBoard', new SoftKeyBoard());
PluginManager.addService("SoftKeyBoard","com.zenexity.SoftKeyBoardPlugin.SoftKeyBoard");
});
*/
3.然後我們在phonegap項目中添加上述兩個檔案
4.在plugin.xml中添加語句(記得修改packageName)
[html]
<plugin name="SoftKeyBoard" value="com.tricedesigns.SoftKeyBoard"/>
5.定義調用的js
[javascript]
function keyBoardClick(){
SoftKeyBoard.skbShow(function () {
// success
},function () {
// fail
});
}
效果如下:
作者:xiaoguang44