Demo02-2:创建Option菜单
来源:互联网 发布:蛙泳世界纪录 知乎 编辑:程序博客网 时间:2024/06/05 03:11
package com.wuqiong.demo02_2;import android.app.Activity;import android.graphics.Color;import android.os.Bundle;import android.view.Menu;import android.view.MenuItem;import android.view.SubMenu;import android.widget.EditText;public class MenuTest extends Activity {private EditText edit;final int BACK_1 = 0x111;final int BACK_2 = 0x112;final int BACK_3 = 0x113; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_menu_test); edit = (EditText) findViewById(R.id.txt); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.menu_test, menu); SubMenu backMenu = menu.addSubMenu("背景颜色"); backMenu.add(0, BACK_1, 0, "红色"); backMenu.add(0, BACK_2, 0, "蓝色"); backMenu.add(0, BACK_3, 0, "绿色"); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); switch(id){ case R.id.font_10: edit.setTextSize(10*2); break; case R.id.font_12: edit.setTextSize(12*2); break; case R.id.font_14: edit.setTextSize(14*2); break; case R.id.font_16: edit.setTextSize(16*2); break; case R.id.font_red: edit.setTextColor(Color.RED); break; case R.id.font_blue: edit.setTextColor(Color.BLUE); break; case R.id.font_green: edit.setTextColor(Color.GREEN); break; case BACK_1: edit.setBackgroundColor(Color.RED); break; case BACK_2: edit.setBackgroundColor(Color.BLUE); break; case BACK_3: edit.setBackgroundColor(Color.GREEN); break; default: break; } return true; }}
<menu xmlns:android="http://schemas.android.com/apk/res/android" ><item android:id="@+id/fontsize" android:title="字体大小" android:icon="@drawable/size" ><menu> <group android:checkableBehavior="single"> <item android:id="@+id/font_10" android:title="10号字体"/> <item android:id="@+id/font_12" android:title="12号字体"/> <item android:id="@+id/font_14" android:title="14号字体"/> <item android:id="@+id/font_16" android:title="16号字体"/> </group></menu></item><item android:id="@+id/fontcolor" android:title="字体颜色" android:icon="@drawable/color" ><menu> <group> <item android:id="@+id/font_red" android:title="红色"/> <item android:id="@+id/font_blue" android:title="蓝色"/> <item android:id="@+id/font_green" android:title="绿色"/> </group></menu></item></menu>
<?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" > <EditText android:id="@+id/txt" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="用于测试的内容" /></LinearLayout>
0 0
- Demo02-2:创建Option菜单
- Demo02:创建Option菜单
- demo02
- Programming Scala第5章demo02 Option类型
- Option Menu 选项菜单
- OPTION Menu菜单
- 选项菜单(option Menu)
- 选项菜单Option Menu
- Android 选项菜单 Option Menu
- js 创建 option
- 动态创建select-option
- 创建菜单
- 创建菜单
- 创建菜单
- javascript动态创建Option选项
- 菜单和列表选项<SELECT><OPTION>
- 动态拼接select的option(菜单级联)
- 菜单和其他资源(2)之创建自己的菜单
- 有了Prezi,你还在用PPT?
- 在JSP中调用Java Class的方法
- Codeforces Round #168 (Div. 1)B 树形dp
- [leetcode][list] Reverse Nodes in k-Group
- day18/day18_IO/FileReaderDemo.java
- Demo02-2:创建Option菜单
- 【练习】面向对象系列(004)——在自定义窗口中画矩形、直线、椭圆
- servlet 3.0笔记之servlet的动态注册
- 归并排序
- JVM实用参数(二)参数分类和即时(JIT)编译器诊断
- hdu 1422 环状最大非负子段
- HBase RegionServer详解
- 怎样做中国的自由译者
- 商品主数据 - Article Master Record