PhoneGap制作的包中创建menu菜单教程
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
相关推荐
Lzs 2020-10-23
聚合室 2020-11-16
零 2020-09-18
Justhavefun 2020-10-22
jacktangj 2020-10-14
ChaITSimpleLove 2020-10-06
Andrea0 2020-09-18
周游列国之仕子 2020-09-15
afanti 2020-09-16
88234852 2020-09-15
YClimb 2020-09-15
风雨断肠人 2020-09-04
卖口粥湛蓝的天空 2020-09-15
stulen 2020-09-15
pythonxuexi 2020-09-06
abfdada 2020-08-26
梦的天空 2020-08-25