Last active
December 16, 2015 01:18
-
-
Save leonguyen/5353562 to your computer and use it in GitHub Desktop.
Android Lab: Option Menu - Add Option Menu
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.example.androidlab; | |
| import android.os.Bundle; | |
| import android.app.Activity; | |
| import android.app.Dialog; | |
| import android.content.Context; | |
| import android.view.Menu; | |
| import android.view.MenuInflater; | |
| import android.view.MenuItem; | |
| import android.view.View; | |
| import android.view.View.OnClickListener; | |
| import android.widget.Button; | |
| import android.widget.Toast; | |
| public class MainActivity extends Activity { | |
| final Context context = this; | |
| @Override | |
| protected void onCreate(Bundle savedInstanceState) { | |
| super.onCreate(savedInstanceState); | |
| setContentView(R.layout.activity_main); | |
| } | |
| @Override | |
| public boolean onCreateOptionsMenu(Menu menu) { | |
| // Inflate the menu; this adds items to the action bar if it is present. | |
| MenuInflater inflater = getMenuInflater(); | |
| inflater.inflate(R.menu.option_menu, menu); | |
| return true; | |
| } | |
| @Override | |
| public boolean onOptionsItemSelected(MenuItem item) { | |
| // TODO Auto-generated method stub | |
| switch (item.getItemId()) { | |
| case R.id.menuAbout: | |
| Toast.makeText(this, "This is Option Menu!", Toast.LENGTH_LONG).show(); | |
| return true; | |
| default: | |
| return super.onOptionsItemSelected(item); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment