zoukankan      html  css  js  c++  java
  • ANDROID OptionMenu 菜单列表

    package com.app.menu;
    
    import android.os.Bundle;
    import android.app.Activity;
    import android.content.Intent;
    import android.view.Menu;
    import android.view.MenuItem;
    import android.webkit.WebView.FindListener;
    import android.widget.ImageButton;
    import android.widget.ImageView;
    
    public class MainActivity extends Activity {
    	/*定义菜单ID	 */
    	private static final int M_CHANGE_FIRST=Menu.FIRST;
    	private static final int M_CHANGE_SECOND=Menu.FIRST+1;
    	private static final int M_CHANGE_HELP=Menu.FIRST+2;  
    	
    	/*创建菜单 重写onCreateOptionMenu 方法	 */
    	@Override
    	public boolean onCreateOptionsMenu(Menu menu) {
    		int idGroup1=3;//创建menu 群组ID
    		//创建menu 顺序ID
    		int orderMenuItem1 = Menu.NONE;
    		int orderMenuItem2 = Menu.NONE+1;
    		int orderMenuItem3 = Menu.NONE+2;
    		menu.add(idGroup1,M_CHANGE_FIRST,orderMenuItem1,"切换第1张图片").setIcon(R.drawable.img1);
    		menu.add(idGroup1,M_CHANGE_SECOND,orderMenuItem2,"切换第2张图片").setIcon(R.drawable.img2);
    		menu.add(idGroup1, M_CHANGE_HELP,orderMenuItem3,"帮助|HELP").setIcon(R.drawable.img3); 
    		// Inflate the menu; this adds items to the action bar if it is present.
    		getMenuInflater().inflate(R.menu.main, menu);
    		return true;
    	}
    	/*选择菜单 重写onOptionItemSelected方法*/
    	@Override
    	public boolean onOptionsItemSelected(MenuItem item) {
    		int id= item.getItemId();//获得menu菜单的id
    		//获得ImageView对象
    		ImageButton  imageView = (ImageButton) findViewById(R.id.imageButton);		
    		 
    		switch (id) {
    			case M_CHANGE_FIRST :				
    				imageView.setImageDrawable(getResources().getDrawable(R.drawable.jpg1 ));
    				break;
    			case M_CHANGE_SECOND :				
    				imageView.setImageDrawable(getResources().getDrawable(R.drawable.jpg2));
    				break;
    			case M_CHANGE_HELP :				
    				Intent intent = new Intent(MainActivity.this,HelpActivity.class);
    				startActivity(intent);
    				break;
    
    			default :
    				break;
    		}
    		return super.onOptionsItemSelected(item);
    	}
    
    	@Override
    	protected void onCreate(Bundle savedInstanceState) {
    		super.onCreate(savedInstanceState);
    		setContentView(R.layout.activity_main);  
    	}
    }
    

  • 相关阅读:
    VS2013 添加 ILDasm
    XmlIgnore的使用
    前端常见跨域解决方案(全)
    网络请求中的cookie与set-Cookie的交互模式的一些问题解析
    各浏览器Cookie大小、个数限制
    Linux常用命令分类
    给博客园中博文的图片添加单击时弹出放大效果——lightbox
    给博客园中博文的图片添加单击时弹出放大效果—— zoom.js
    CSS3新单位vw、vh、vmin、vmax使用详解
    session,cookie,sessionStorage,localStorage的相关设置以及获取删除
  • 原文地址:https://www.cnblogs.com/aikongmeng/p/3697406.html
Copyright © 2011-2022 走看看