1.在主java檔public class app extends DroidGap後添加如下代碼:

簡單示例:

@Override
public boolean onCreateOptionsMenu(Menu menu) {
menu.add(0,1,1,R.string.about);
menu.add(0,2,2,R.string.navigation);
menu.add(0,3,3,R.string.exit);
// TODO Auto-generated method stub
return super.onCreateOptionsMenu(menu);
 } @Override public boolean onOptionsItemSelected(MenuItem item) {
 if(item.getItemId()==3){ finish();
 }
 if(item.getItemId()==1){
}
if(item.getItemId()==2){
 } return super.onOptionsItemSelected(item);
}
  
 
 完整示例

package com.vae.cn;
import android.os.Bundle;
import android.view.Menu;
 import android.view.MenuItem;
import com.phonegap.*;
public class app extends DroidGap {
/** Called when the activity is first created. */
@Override public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.setIntegerProperty("splashscreen", R.drawable.splash);
super.loadUrl("file:///android_asset/www/index.html", 4500); }
@Override
public boolean onCreateOptionsMenu(Menu menu) {
 menu.add(0,1,1,R.string.about);
 menu.add(0,2,2,R.string.navigation);
 menu.add(0,3,3,R.string.exit);
 // TODO Auto-generated method stub
return super.onCreateOptionsMenu(menu); }
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if(item.getItemId()==3){
finish();
}
 if(item.getItemId()==1){
} if(item.getItemId()==2){
}
 return super.onOptionsItemSelected(item);
 } }
2.在res/values目錄下的string.xml中添加如下鍵對值

簡單示例

<string name="exit">退出</string>
<string name="about">關於</string>
<string name="navigation">導航</string>
 
 完整示例

<?xml version="1.0" encoding="utf-8"?>
<resources> <string name="hello">app</string>
<string name="exit">退出</string>
<string name="about">關於</string>
 <string name="navigation">導航</string>
 </resources>
創作者介紹
創作者 shadow 的頭像
shadow

資訊園

shadow 發表在 痞客邦 留言(0) 人氣()