我现在尝试创建一个菜单,稍后将其嵌入到导航抽屉中。我正在使用示例插件,然后修改index.html和index.js以显示插件信息。我没有收到任何错误,可以看到已经安装了插件文件(如XML文件和Java文件),但是根本看不到菜单。我尝试在chrome中调试它,但在网络/控制台中看不到与该插件相关的任何内容。我希望在Webview上显示此视图。我究竟做错了什么?主要文章来源为here
index.html:
<meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: https://ssl.gstatic.com 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *; img-src 'self' data: content:;">
<meta name="format-detection" content="telephone=no">
<meta name="msapplication-tap-highlight" content="no">
<meta name="viewport" content="user-scalable=no, initial-scale=0.7, maximum-scale=1, minimum-scale=1, width=device-width">
<link rel="stylesheet" type="text/css" href="css/index.css">
<title>ourapp</title>
</head>
<body>
<div class="app">
<h1>ourapp</h1>
<div id="deviceready" class="blink">
<p class="event listening">Connecting to Device</p>
<p class="event received">Device is Ready</p>
</div>
<input id="bookmark" type="text"/>
<button id="btnAdd">ADD ITEM</button>
<br/>
<button id="btnDeviceInfo">GET DEVICE INFO</button>
<br/>
<button id="btnToast">SHOW TOAST</button>
<br>
<button id="btnUrl">OPEN URL</button>
<br/>
</div>
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="js/index.js"></script>
</body>
</html>
index.js:
var app = {
// Application Constructor
initialize: function() {
document.addEventListener('deviceready', this.onDeviceReady.bind(this), false);
},
// deviceready Event Handler
//
// Bind any cordova events here. Common events are:
// 'pause', 'resume', etc.
onDeviceReady: function() {
window.plugins.toast.showLongBottom('Use the back button to return to main.');
document.getElementById("btnAdd").addEventListener("click", app.addItem);
document.getElementById("btnToast").addEventListener("click", app.showToast);
document.getElementById("btnDeviceInfo").addEventListener("click", app.showDeviceInfo);
document.getElementById("btnUrl").addEventListener("click", app.openWeb);
this.receivedEvent('deviceready');
},
// Update DOM on a Received Event
receivedEvent: function(id) {
var parentElement = document.getElementById(id);
var listeningElement = parentElement.querySelector('.listening');
var receivedElement = parentElement.querySelector('.received');
listeningElement.setAttribute('style', 'display:none;');
receivedElement.setAttribute('style', 'display:block;');
console.log('Received Event: ' + id);
},
addItem: function() {
console.log("Plugin ADD ITEM CALLED " + HybridBridge);
var item = document.getElementById("bookmark").value;
HybridBridge.addItem(item,function(){console.log("Hybrid Bridge Success")},function(e){console.log("Hybrid Bridge Error" + e)});
},
showDeviceInfo: function(){
var message = 'Cordova version: ' + device.cordova;
message += '\n\nDevice Model: ' + device.model;
message += '\n\nDevice Version (Android): ' + device.version;
alert(message);
},
showToast: function(){
window.plugins.toast.showShortCenter('PHONEGAP IS AWESOME!!!');
},
openWeb: function(){
var url = "http://phonegap.com"
window.open(url)
}
};
app.initialize();
从下面的屏幕快照中可以看到,我在这里(同样在AndroidManifest.xml中)有插件java文件MyListActivity,在layouts文件夹中也有layout文件。