参考 http://www.crifan.com/android_add_menu/


响应menu

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
    Log.e(TAG,"onCreateOptionMenu");
    // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.activity_main, menu);
        menu.add("插入");


        
        return true;
    }



响应menu的条目
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        Log.e("ZHANGBIN","create option menu");
        // Handle item selection
        switch (item.getItemId()) {
            case R.id.menu_discard:
             Toast.makeText(MainActivity.this, "Menu Discard cliked", Toast.LENGTH_SHORT).show();
                return true;
            case R.id.menu_send:
             Toast.makeText(MainActivity.this, "Menu Send cliked", Toast.LENGTH_SHORT).show();
            
                return true;
            default:
                return super.onOptionsItemSelected(item);
        }
    }



menu的布局xml:


            android:id="@+id/menu_discard"


        android:orderInCategory="1"
        android:showAsAction="ifRoom|withText"
        android:title="试试"/>
   
   
            android:id="@+id/menu_send"


        android:orderInCategory="2"
        android:showAsAction="ifRoom|withText"
        android:title="看看"/>


没深入学习,可以参考

http://tech.it168.com/a2011/1031/1266/000001266576_all.shtml

学习下每个item的xml给定的属性的意义。

更多相关文章

  1. 【Android】控件和基本事件响应的三种方式
  2. Android(安卓)PopupWindow & some problems
  3. 学习进度十二
  4. android学习日常3-15 关于单选框附加监听的复习
  5. Android(安卓)MediaProjection学习(一)之和ImageReader实现屏幕截
  6. 自学android——AutoCompleteTextView的使用
  7. 为ListActivity 添加Button
  8. 【问题处理】arcgis运行在android studio上jar包冲突解决
  9. 【Android开发学习43】OpenGL ES教程VI之纹理贴图(原文对照)

随机推荐

  1. Android系统集成有源码的第三方库和程序
  2. Android中用Application类实现全局数据变
  3. android 代码设置EditText的hint字符
  4. android通过包名跳转到系统闹钟
  5. android 兼容各个版本 读取通讯录
  6. Android中的URI 和Uri
  7. Android Hook 机制之简单实战
  8. webservice二进制文件传输
  9. [置顶] Android类加载之PathClassLoader
  10. Android(安卓)Smali第一次完整的见面