1. Menus (menu)
1. Definition in Menu\menu.xml
<Menuxmlns:android= "Http://schemas.android.com/apk/res/android"Xmlns:tools= "Http://schemas.android.com/tools"Tools:context= "Com.mytest.testbase.MainActivity" > <ItemAndroid:id= "@+id/showdialog"android:orderincategory= "+"android:showasaction= "Never"Android:title= "Dialog"/> <ItemAndroid:id= "@+id/showtoast"android:orderincategory= "+"android:showasaction= "Never"Android:title= "Toast"/> </Menu>
View Code
2, activity in the code
@Override Public BooleanOncreateoptionsmenu (Menu menu) {//inflate the menu; This adds items to the action bar if it is present.getmenuinflater (). Inflate (R.menu.main, menu); return true; } @Override Public Booleanonoptionsitemselected (MenuItem item) {intID =Item.getitemid (); if(id = =r.id.showdialog) {NewAlertdialog.builder ( This). Settitle ("Test"). Setpositivebutton ("Off",NewDialoginterface.onclicklistener () {@Override Public voidOnClick (Dialoginterface Dialog,intwhich) {Toast.maketext (mainactivity). This, "ShowDialog", Toast.length_short). Show (); }}). Show (); } if(id = =r.id.showtoast) {Toast.maketext ( This, "Toast", Toast.length_short). Show (); } return Super. onoptionsitemselected (item); }View Code
Second, assets Resources read
1. Place the file in the assets.
2. Read in activity
InputStream is = Getbasecontext (). Getassets (). open (Dbservice.db_name);
Android Resources: Menus and assets