Android OptionMenu
1、Java
package com.fish.helloworld; import android.app.Activity;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView; public class MainActivity extends Activity { private Button m_Button; public static final int RED_MENU_ID = Menu.FIRST;
public static final int GREEN_MENU_ID = Menu.FIRST + 1;
public static final int BLUE_MENU_ID = Menu.FIRST + 2; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.skeleton_activity); m_Button = (Button)findViewById(R.id.button1);
} @Override
public boolean onCreateOptionsMenu(Menu menu){
super.onCreateOptionsMenu(menu);
menu.add(0, RED_MENU_ID, 0, "RED");
menu.add(0, GREEN_MENU_ID, 0, "GREEN");
menu.add(0, BLUE_MENU_ID, 0, "BLUE");
return true;
} @Override
public boolean onOptionsItemSelected(MenuItem item){
switch(item.getItemId()){
case RED_MENU_ID:
m_Button.setBackgroundColor(Color.RED);
m_Button.setText("RED");
return true;
case GREEN_MENU_ID:
m_Button.setBackgroundColor(Color.GREEN);
m_Button.setText("GREEN");
return true;
case BLUE_MENU_ID:
m_Button.setBackgroundColor(Color.BLUE);
m_Button.setText("BLUE");
return true;
} return super.onOptionsItemSelected(item);
}
}
2、XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" > <Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" /> </LinearLayout>
Android OptionMenu的更多相关文章
- ANDROID OptionMenu 菜单列表
package com.app.menu; import android.os.Bundle; import android.app.Activity; import android.content. ...
- Android:OptionMenu
MainActivity: package com.example.optionmenu; import android.content.Intent; import android.os.Bundl ...
- Android开发之Menu:OptionMenu(选项菜单)、ContextMenu(上下文菜单)、SubMenu(子菜单)
菜单的概念,现在已经很普及了.Windows系统.Mac.桌面版Linux.Java Swing等,都有可视化菜单.一.Android平台3种菜单 选项菜单(OptionMenu).上下文菜单(Co ...
- android之OptionMenu
一.现在我给大家介绍两个不同版本的模拟器(2.3.3和4.0.3) 1.布局文件 (1)打开“res/layout/activity_main.xml”文件. 先看mian布局文件 <Relat ...
- Android 菜单(OptionMenu)
菜单是用户界面中最常见的元素之一,使用非常频繁,在Android中,菜单被分为如下三种,选项菜单(OptionsMenu).上下文菜单(ContextMenu)和子菜单(SubMenu). 一.概述 ...
- android 为activity添加optionMenu选项菜单
<menu xmlns:android="http://schemas.android.com/apk/res/android"> <group android: ...
- Android之ContextMenu的使用方法以及与OptionMenu的区别
>> ContextMenu是android的context menu上下文菜单,选择某项VIEW后长按menu键,就会显示出来.比如EditeText就可以通过长按来弹出拥有“cut”, ...
- 【转】Android 菜单(OptionMenu)大全 建立你自己的菜单--不错
原文网址:http://www.cnblogs.com/salam/archive/2011/04/04/2005329.html 菜单是用户界面中最常见的元素之一,使用非常频繁,在Android中, ...
- Android 菜单(OptionMenu)大全 建立你自己的菜单
转自:http://www.cnblogs.com/salam/archive/2011/04/04/2005329.html 菜单是用户界面中最常见的元素之一,使用非常频繁,在Android中,菜单 ...
随机推荐
- Ecshop(二次开发) - 后台添加左侧菜单导航
1.链接地址:修改 admin\includes\inc_menu.php 文件. $modules['17_syn_data']['view_syn'] = 'synchroni ...
- 如何限制textarea文本框的输入字数
代码实例如下: <!doctype html><html><head><meta charset="UTF-8"><title ...
- Getting started with SciPy for .NET
Getting started with SciPy for .NET 1.) IronPython Download and install IronPython 2.7, this will re ...
- List集合去重的一种方法 z
需要对一个List<Model>集合去重,情况是该集合中会出现多个Name属性值相同的,但是其他属性值不同的数据. 在这种情况下,需求要只保留其中一个就好. 我觉得遍历和HashSet都不 ...
- UITapGestureRecognizer 的用法
最近在项目中用到了手势操作,键盘回收时还是挺常用的,现在总结下,多谢网络上大神们的分享. 先分享下我在项目中用的代码: UITapGestureRecognizer * mytap=[[UITapGe ...
- Java中-XMX -xmn 是什么的缩写
这个应该是 eclipse 的配置文件 eclipse.ini 中的配置语句.在配置文件中直接传递给 java vm 的参数并不多,调用形式是这样的: 1 eclipse [normal argume ...
- 第10章 Posix 信号量
10.1 概述 10.1.1 信号量类型 Posix有名信号量:使用Posix IPC名字,可用于进程或线程间同步: Posix基于内存的信号量:也叫做无名信号量,存放在共享内存中,可用于进程或线程间 ...
- 无侵入方面编程-用HttpModule+SoapExtension监视页面执行参数(一)
先简单介绍一下项目吧,我们这个项目是用VS2003开发的,老早一个项目.WEB前端机+业务处理(WebService层)+数据库分别布置在不同的计算机上. 现在老总有一个需求,要统计出每个页面的执行时 ...
- 判断Windows操作系统的版本
private void Form1_Load(object sender, EventArgs e) { if (!IsWin7()) { Application.Exit(); } } bool ...
- 安装LINUX X86-64的10201出现链接ins_ctx.mk错误
在安装linux X86-64的Oracle10201时,在链接过程中出现了这个错误. 详细错误信息为: Error in invoking target ‘install’ of makefile ...