临碣秘藏 2013-07-10
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){ super.loadUrl("file:///android_asset/www/about.html"); } if(item.getItemId()==2){ super.loadUrl("file:///android_asset/www/index.html"); } 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){ super.loadUrl("file:///android_asset/www/about.html"); } if(item.getItemId()==2){ super.loadUrl("file:///android_asset/www/index.html"); } 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>
转自:mobile.51cto.com/web-322294.htm