Created
February 1, 2017 05:26
-
-
Save alfianyusufabdullah/178897dd9c16efc40238e5d6a221f83a to your computer and use it in GitHub Desktop.
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.jonesrandom.optionsmenutoolbar; | |
| import android.support.v7.app.AppCompatActivity; | |
| import android.os.Bundle; | |
| import android.support.v7.widget.Toolbar; | |
| import android.view.Menu; | |
| import android.view.MenuItem; | |
| import android.widget.Toast; | |
| public class MainActivity extends AppCompatActivity { | |
| Toolbar myToolbar; | |
| @Override | |
| protected void onCreate(Bundle savedInstanceState) { | |
| super.onCreate(savedInstanceState); | |
| setContentView(R.layout.activity_main); | |
| myToolbar = (Toolbar) findViewById(R.id.my_toolbar); | |
| /// mengatur Toolbar kedalam Support Action Bar | |
| setSupportActionBar(myToolbar); | |
| } | |
| @Override | |
| public boolean onCreateOptionsMenu(Menu menu) { | |
| /// Meng inflate file Menu | |
| getMenuInflater().inflate(R.menu.my_menu, menu); | |
| return super.onCreateOptionsMenu(menu); | |
| } | |
| @Override | |
| public boolean onOptionsItemSelected(MenuItem item) { | |
| int ID = item.getItemId(); | |
| switch (ID) { | |
| case R.id.menu_1: | |
| Toast.makeText(MainActivity.this, "Agan Klik Menu 1", Toast.LENGTH_SHORT).show(); | |
| break; | |
| case R.id.menu_2: | |
| Toast.makeText(MainActivity.this, "Agan Klik Menu 2", Toast.LENGTH_SHORT).show(); | |
| break; | |
| case R.id.menu_3: | |
| Toast.makeText(MainActivity.this, "Agan Klik Menu 3", Toast.LENGTH_SHORT).show(); | |
| break; | |
| } | |
| return super.onOptionsItemSelected(item); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment