Option Menu:
Option Menu is a drop down menu containing options, and appears when a users clicks on Menu button.
For Ex:
We can create an Option Menu with following :
Create a new folder named "Menu" in res folder
inside this Menu folder create .xml file
here I have created option.xml xml for the option menu in above Image
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:id="@+id/ChangeColor"
android:icon="@drawable/setting"
android:title="Settings"
/>
<item android:id="@+id/phoneInformation"
android:icon="@drawable/phone"
android:title="My Phone Information" />
<item android:id="@+id/callInfo"
android:icon="@drawable/callinfo"
android:title="In and Out Call Info" />
<item android:id="@+id/email"
android:icon="@drawable/mail"
android:title="Mail to Developer" />
</menu>
Override onCreateOptionMenu method and inflate the .xml (here options.xml) inside method
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.options, menu);
return true;
}
When the user selects an item from the options menu (including action items in the action bar), the system calls your activity's
To Handle click events override onOptionsItemSelected method
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection
switch (item.getItemId()) {
case R.id.ChangeColor:
// write code to execute when clicked on this option
return true;
case R.id.phoneInformation:
// write code to execute when clicked on this option
return true;
case R.id.callInfo:
// write code to execute when clicked on this option
return true;
case R.id.email:
// write code to execute when clicked on this option
return true;
default:
return super.onOptionsItemSelected(item);
}
}
Customizing Toast In Android
Showing Toast for Longer Time
Customizing the Display Time of Toast
Using TimePickerDialog and DatePickerDialog In android
Animating A Button In Android
Populating ListView With DataBase
Customizing Checkboxes In Android
Increasin Size of Checkboxes
Android ProgressBar
Designing For Different Screen Sizes
Handling Keyboard Events
Understanding Android Manifest File of your android app
Working with Linear Layout (With Example)
Nested Linear Layout (With Example)
Table Layout
Frame Layout(With Example)
Absolute Layout
Grid Layout
Activity Life Cycle
Starting Activity For Result
Sending Data from One Activity to Other in Android
Returning Result from Activity
Using CheckBoxes in Android
Using AutoCompleteTextView in Android
Grid View
Customizing the Display Time of Toast
Customizing Toast At Runtime
Adding Image in Toast
Showing Toast for Longer Time
Adding Radio Buttons In Dialog
Adding Check Boxes In Dialog
Creating Customized Dialogs in Android
Adding EditText in Dialog
Creating Dialog To Collect User Input
How To Receive SMS
Accessing Inbox In Android
Creating Context Menu In Android
How to Forward an Incoming Call In Android
CALL States In Android
How To Vibrate The Android Phone
Sending Email In Android
Opening a webpage In Browser
How to Access PhoneBook In Android
Prompt User Input with an AlertDialog
Reading and Writing files to SD Card
Creating Table In Android
Inserting, Deleting and Updating Records In Table in Android
How to Create DataBase in Android
Accessing Inbox In Android
Option Menu is a drop down menu containing options, and appears when a users clicks on Menu button.
For Ex:
We can create an Option Menu with following :
- Create a menu xml
- Register the menu in Activity
- Write code to Handle the Clicks on menu items
1: Create xml for menu
Create a new folder named "Menu" in res folder
inside this Menu folder create .xml file
here I have created option.xml xml for the option menu in above Image
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:id="@+id/ChangeColor"
android:icon="@drawable/setting"
android:title="Settings"
/>
<item android:id="@+id/phoneInformation"
android:icon="@drawable/phone"
android:title="My Phone Information" />
<item android:id="@+id/callInfo"
android:icon="@drawable/callinfo"
android:title="In and Out Call Info" />
<item android:id="@+id/email"
android:icon="@drawable/mail"
android:title="Mail to Developer" />
</menu>
android:id
- A resource ID that's unique to the item, which allows the application can recognize the item when the user selects it.
android:icon
- An image to use as the item's icon.
android:title
- A tittle to show.
2: Register In Activity
Override onCreateOptionMenu method and inflate the .xml (here options.xml) inside method
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.options, menu);
return true;
}
3: Handle Click Events
When the user selects an item from the options menu (including action items in the action bar), the system calls your activity's
onOptionsItemSelected()
method. This method passes the MenuItem
selected. You
can identify the item by calling getItemId()
, which returns the unique
ID for the menu item (defined by the android:id
attribute in the menu resource To Handle click events override onOptionsItemSelected method
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection
switch (item.getItemId()) {
case R.id.ChangeColor:
// write code to execute when clicked on this option
return true;
case R.id.phoneInformation:
// write code to execute when clicked on this option
return true;
case R.id.callInfo:
// write code to execute when clicked on this option
return true;
case R.id.email:
// write code to execute when clicked on this option
return true;
default:
return super.onOptionsItemSelected(item);
}
}
Advance Android Topics
Customizing Toast In Android
Showing Toast for Longer Time
Customizing the Display Time of Toast
Using TimePickerDialog and DatePickerDialog In android
Animating A Button In Android
Populating ListView With DataBase
Customizing Checkboxes In Android
Increasin Size of Checkboxes
Android ProgressBar
Designing For Different Screen Sizes
Handling Keyboard Events
More Android Topics
Android : Introduction
Eclipse Setup for Android Development
Configuring Eclipse for Android DevelopmentBegging With Android
Creating Your First Android ProjectUnderstanding Android Manifest File of your android app
Working With Layouts
Understanding Layouts in AndroidWorking with Linear Layout (With Example)
Nested Linear Layout (With Example)
Table Layout
Frame Layout(With Example)
Absolute Layout
Grid Layout
Activity
Activity In AndroidActivity Life Cycle
Starting Activity For Result
Sending Data from One Activity to Other in Android
Returning Result from Activity
Working With Views
Using Buttons and EditText in AndroidUsing CheckBoxes in Android
Using AutoCompleteTextView in Android
Grid View
Toast
Customizing Toast In AndroidCustomizing the Display Time of Toast
Customizing Toast At Runtime
Adding Image in Toast
Showing Toast for Longer Time
Dialogs In Android
Working With Alert DialogAdding Radio Buttons In Dialog
Adding Check Boxes In Dialog
Creating Customized Dialogs in Android
Adding EditText in Dialog
Creating Dialog To Collect User Input
DatePicker and TimePickerDialog
Using TimePickerDialog and DatePickerDialog In androidWorking With SMS
How to Send SMS in AndroidHow To Receive SMS
Accessing Inbox In Android
ListView:
Populating ListView With DataBaseMenus In Android
Creating Option MenuCreating Context Menu In Android
TelephonyManager
Using Telephony Manager In AndroidWorking With Incoming Calls
How To Handle Incoming Calls in AndroidHow to Forward an Incoming Call In Android
CALL States In Android
Miscellaneous
Notifications In AndroidHow To Vibrate The Android Phone
Sending Email In Android
Opening a webpage In Browser
How to Access PhoneBook In Android
Prompt User Input with an AlertDialog
Storage: Storing Data In Android
Shared Prefferences In Android
SharedPreferences In AndroidFiles: File Handling In Android
Reading and Writing files to Internal StoarageReading and Writing files to SD Card
DataBase : Working With Database
Working With Database in AndroidCreating Table In Android
Inserting, Deleting and Updating Records In Table in Android
How to Create DataBase in Android
Accessing Inbox In Android
WOW just what I was searching for. Came here by searching
ReplyDeletefor snowmobile
my weblog - anxiety disorder
I need to to thank you for this fantastic read!! I absolutely loved every bit
ReplyDeleteof it. I've got you bookmarked to look at new things you post…
Feel free to visit my page; http://heraudition.com/SheriFwn
A fascinating discussion is worth comment.
ReplyDeleteThere's no doubt that that you should write more about this subject, it may not be a taboo subject but generally folks don't speak about such topics.
To the next! All the best!!
Visit my page ... Juicing Beets
Keep on working, great job!
ReplyDeleteFeel free to visit my web blog; Juicing wheatgrass
This comment has been removed by the author.
ReplyDeleteAw, this was an extremely nice post. Taking a
ReplyDeletefew minutes and actual effort to generate a good article…
but what can I say… I hesitate a whole lot and never
seem to get nearly anything done.
Check out my site - taco bell locations
Finally i have discover what i am searching for
ReplyDeleteMy Blog : learn24bd
Thanks for these posts :) its really helpful.
ReplyDeleteI have problem with option menus i cannot see icons in option menu just the title is been displayed. Please can you tell me where am going wrong
It's actually a nice and helpful piece of information. I am happy that you just shared this useful info with us.
ReplyDeletePlease stay us informed like this. Thank you for sharing.
We're a group of volunteers and opening a new scheme in our
ReplyDeletecommunity. Your site offered us with valuable information to work on. You have done a formidable job and
our whole community will be grateful to you.
Good post but I was wanting to know if you could
ReplyDeletewrite a litte more on this subject? I'd be very thankful if you
could elaborate a little bit more. Many thanks!
Link exchange is nothing else but it is just placing the
ReplyDeleteother person's weblog link on your page at appropriate place and other person will also do same in support of
you.
It is perfect time to make a few plans for the long run and it
ReplyDeleteis time to be happy. I have learn this post and if I could I wish to suggest
you some interesting issues or advice. Perhaps you can write subsequent articles regarding this article.
I desire to read more issues about it!
I visited various sites but the audio quality for audio songs existing at this web page is really
ReplyDeletemarvelous.
Hey There. I discovered your weblog using msn. This is a really neatly written article.
ReplyDeleteI will be sure to bookmark it and come back to read more of your useful information. Thank you for the post.
I'll definitely return.