Andriod phonegap(Cordova)彈出軟體盤功能

來源:互聯網
上載者:User

貌似沒什麼用的軟體盤彈出的功能,利用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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.