Android Tutorial(3)Android Menu Example - Utilizing Menus
Trouble Shooting First
Error Message:
[INFO] :13: error: No resource identifier found for attribute 'textIsSelectable' in package 'android'
[ERROR] Error when generating sources.
org.apache.maven.plugin.MojoExecutionException:
at com.jayway.maven.plugins.android.phase01generatesources.GenerateSourcesMojo.generateR(GenerateSourcesMojo.java:446)
at com.jayway.maven.plugins.android.phase01generatesources.GenerateSourcesMojo.execute(GenerateSourcesMojo.java:162)
Solution:
That is because of the API Level. So try to get rid of this from XML configurations.
Error Message:
GcmBaseIntentService registration error account_missing
Solution:
Directly use Setting to login on with a google account.
I plan to note how to set the menus.
1. Create the XML file
Create the menu file from [res]------>[menu]----->[New Android XML File] ----->
[Resource Type] ----> Menu
Root Element -----> menu
Just click [Add Item] to add menus.
I set these properties ---> id, Title, Icon[@drawable/menu_name] menu_name is the name of the icon file in drawable-hdpi.
2. Modify the Implementation Activity Class
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.options_menu_all, menu);
returntrue;
}
publicboolean onOptionsItemSelected(MenuItem item) {
boolean result = true;
try {
switch (item.getItemId()) {
caseR.id.item_list_all_person:
startActivity(new Intent(this, PersonListActivity.class));
return true;
caseR.id.item_get_one_person:
startActivity(new Intent(this, GetOnePersonActivity.class));
return true;
caseR.id.item_gcm_demo:
startActivity(new Intent(this, DemoActivity.class));
return true;
caseR.id.item_list_product:
startActivity(new Intent(this, ProductsListActivity.class));
return true;
default:
returnsuper.onOptionsItemSelected(item);
}
} catch (Exception error) {
Log.d(TAG, "About_onOptionsItemSelected failed");
}
return result;
}
Some Tips:
1. If you want to show the selected item in menu. We can ask the different activity load different menu XML files with different icons.
2. We can also put the implementation of the menu in abstract class of the activities which extended from base class. That is to say, just put the menu in the base class is fine.
References:
http://vimaltuts.com/android-tutorial-for-beginners/android-menu-example
分享到:
相关推荐
spring的安全框架演示demo,这个是简单的,适合初学者
【标题】:“lerna-tutorial-example-master.rar”指的是一个使用Lerna管理的多包项目教程的压缩文件。Lerna是一个流行的JavaScript工具,用于在单个仓库中管理多个独立发布的npm包,非常适合大型代码库和组件化开发...
《Python库:hypermodern_tutorial-0.1.2-py3-none-any.whl详解》 在Python的开发世界中,库是构建复杂应用程序的重要基石。它们提供了预先编写的功能,帮助开发者快速实现特定任务,而无需从零开始。本文将深入...
资源来自pypi官网。 资源全名:hypermodern_tutorial-0.1.2-py3-none-any.whl
63.[开源][安卓]roman10-android-tutorial-master roman10-android-tutorial包含了android tutorial的所有源代码。
OpenGL SuperBible Comprehensive Tutorial and Reference, 7th Edition - 2015
android-unit-testing-tutorial Code project corresponding to a serials of tutorial posts for android unit testing 本文是一系列发表在我的个人博客,关于安卓单元测试的文章的实例代码。 代码与文章的对应关系...
android-app-bootstrap ...A starting tutorial for Android application. native-in-practice Output npmcdn.com: android_app_bootstrap-debug.apk License The MIT License (MIT) Copyright (c) 2015 xdf
For a complete tutorial write-up, please see here: http://mcuhq.com/27/simple-android-bluetooth-application-with-arduino-example This is a simple demo app that creates buttons to toggle ON/OFF the ...
rust-by-example-ext:Rust by Example-扩展版
【标题】"client-sdk-android-tutorial-voice-phone-to-app-kotlin" 涉及的是一个使用Kotlin编写的Android客户端SDK教程,主要讲解如何实现从电话到应用的语音通信功能。这个项目可能已经被弃用,但其源代码和文档...
iBATIS-SqlMaps-2-Tutorial_cniBATIS-SqlMaps-2-Tutorial_cn.pdf.pdfiBATIS-SqlMaps-2-Tutorial_cn.pdfiBATIS-SqlMaps-2-Tutorial_cn.pdf
从github下载的UVM入门教程。 网页版教程 http://cluelogic.com/2011/07/uvm-tutorial-for-candy-lovers-overview/ 原始地址 https://github.com/cluelogic/uvm-tutorial-for-candy-lovers
UG871 - Vivado Design Suite Tutorial: High-Level Synthesis (v2019.1),UG871文档最新版本,适用于vivado 2017以及之后的版本
本资源为Cheat Engine 训练教程,本教程将尝试讲解在游戏中作弊的一些基本知识,并帮助你熟悉 Cheat Engine 的使用方法。通过本应用,可以帮助新人快速入门CE的基本操作方法。如查找数据,修改数据等等
rCore-Tutorial-v3是基于Rust语言构建的开源操作系统模拟环境,主要针对RISC-V架构,同时也支持K210开发板。这个教程旨在帮助开发者理解和学习操作系统的基本原理,以及Rust在系统编程中的应用。 rCore操作系统是用...
OpenCV-Python-Tutorial-master OpenCV-Python-Tutorial-master OpenCV-Python-Tutorial-master‘ opencv的演习源代码和图片
【标题】"Video-Tutorial--MySQL-ANDROID.rar_android" 提供了一个关于在Android平台上使用MySQL数据库的视频教程。这个教程可能涵盖了如何在Android应用中集成MySQL数据库,以便存储和检索数据,这对于移动应用开发...
01 - Intro basic GUI - PyQt with Python GUI Programming tutorial.mp4 02 - Application Structure - PyQt with Python GUI Programming tutorial.mp4 03 - Buttons - PyQt with Python GUI Programming tutorial...