重温2 在Activity中使用Menu
2016-06-19 10:52
357 查看
1、引用string.xml中的字符串
1) 代码中 R.string.hello_world
2) XML中@string/hello_world
2、AndroidManifest
android:label指定Activity中标题栏的内容、也是应用程序的名称。
intent-filter中的
3、Toast duration
在menu文件夹下main.xml中添加
重写onCreateOptionsMenu()
1) 代码中 R.string.hello_world
2) XML中@string/hello_world
2、AndroidManifest
<activity android:name=".MainActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter>
android:label指定Activity中标题栏的内容、也是应用程序的名称。
intent-filter中的
<action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" />标识MainActivity是应用的主程序。
3、Toast duration
Toast.LENGTH_SHORT//2S Toast.LENGTH_LONG//3.5s4、在Activity中使用Menu
在menu文件夹下main.xml中添加
<item android:id="@+id/add_item" android:title="@string/add"/> <item android:id="@+id/remove_item" android:title="@string/remove"/>
重写onCreateOptionsMenu()
<span style="white-space:pre"> </span>@Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true;//表示允许将菜单显示出来 }重写 onOptionsItemSelected()
<span style="white-space:pre"> </span>@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.add_item: Toast.makeText(this, "add", Toast.LENGTH_SHORT).show(); break; case R.id.remove_item: Toast.makeText(this, "remove", Toast.LENGTH_SHORT).show(); break; default: }
相关文章推荐
- 安卓eclipse开发闪退
- Java关键字的大致含义
- 【剑指offer】数值的整数次方
- acm_畅通工程
- Linux内核部件分析 设备驱动模型之device
- JDK与设计模式:代理模式
- asp.net利用activeX获取客户端IP MAC 计算机名
- 软件工程-附加作业
- 附加题
- 【剑指offer】二进制中1的个数
- Linux内核部件分析 设备驱动模型的基石kobject
- Linux 系统应用编程——网络编程(socket编程)
- Greenplum或DeepGreen数据库对象的使用和管理
- Linux内核部件分析 更强的链表klist
- 使用opencv下的SVM分类器
- Linux内核部件分析 记录生命周期的kref
- Ruby的DevKit名词解释
- Linux 系统应用编程——网络编程(基础篇)
- 附加作业
- C#开发Windows服务