Android自动生成启动Activity的特定按钮
16lz
2021-01-26
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
@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
更多相关文章
- 记录targetSdkVersion升级以后Android遇到的一些问题
- Android(安卓)继承ViewGroup必须重写onMeasure方法和onLayout方
- Android之启动应用源码分析
- Android之Service相关
- 关于overridePendingTransition效果在1.6版本中会出现VerifyErro
- Android:Activity(九):Fragment管理与Fragment事务
- Android——SharedPreferences数据存储
- Android中间层c语言log打印方法
- Xamarin.Forms QR Code Scan 二维码扫描的Android(安卓)App