Android自动生成启动Activity的特定按钮 声明一个Activity,使用ACTION_MAIN作为Action,CATEGORY_DEFAULT作为Category,之后在调用Activity中,引入如下代码就可以自动生成所有匹配Action和Category的Activity的启动菜单了。
@Override
public boolean onCreateOptionsMenu(Menumenu) {
Log.i(
"TestActivity","OptionsMenuCreated");
super.onCreateOptionsMenu(menu);
//menu.add(1,0,0,"EDIT");

//CreateanIntentthatdescribestherequirementstofulfill,tobeincluded
//inourmenu.TheofferingappmustincludeacategoryvalueofIntent.CATEGORY_ALTERNATIVE.
Intentintent=newIntent(Intent.ACTION_MAIN,getIntent().getData());
intent.addCategory(Intent.CATEGORY_ALTERNATIVE);

//Searchfor,andpopulatethemenuwith,acceptableofferingapplications.
menu.addIntentOptions(
1,//Menugroup
0,//UniqueitemID(none)
0,//Orderfortheitems(none)
this.getComponentName(),//ThecurrentActivityname
null,//Specificitemstoplacefirst(none)
intent,//Intentcreatedabovethatdescribesourrequirements
0,//Additionalflagstocontrolitems(none)
null);//ArrayofMenuItemsthatcorrolatetospecificitems(none)

returntrue;
}


---------------------------------------------------------
专注移动开发
Android, Windows Mobile, iPhone, J2ME, BlackBerry, Symbian

更多相关文章

  1. 记录targetSdkVersion升级以后Android遇到的一些问题
  2. Android(安卓)继承ViewGroup必须重写onMeasure方法和onLayout方
  3. Android之启动应用源码分析
  4. Android之Service相关
  5. 关于overridePendingTransition效果在1.6版本中会出现VerifyErro
  6. Android:Activity(九):Fragment管理与Fragment事务
  7. Android——SharedPreferences数据存储
  8. Android中间层c语言log打印方法
  9. Xamarin.Forms QR Code Scan 二维码扫描的Android(安卓)App

随机推荐

  1. Android(安卓)设置圆角背景
  2. android 判断是否有网络工具类
  3. android检查手机网络状态
  4. 【MarsChen】D01_Android一日游
  5. 布局与深化
  6. 2.5.1 使用alertDialog
  7. android sd卡读取数据库
  8. 2.5.4 使用popupWindow
  9. Android设置Activity背景为透明style
  10. ANDROID EMULATOR 4 启动报错