<menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" tools:context=".MainActivity"> <item android:id="@+id/SigningUp" showAsAction="ifRoom|withText" android:title="ثبت نام"/> </menu>
public static final int SIGN_UP_ID = Menu.FIRST; public static final int EXIT_APP_ID = Menu.FIRST + 1; @Override public boolean onCreateOptionsMenu(Menu menu) { boolean result = super.onCreateOptionsMenu(menu); MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.menu_main, menu); menu.add(0, SIGN_UP_ID, 0, R.string.sign_up); menu.add(0, EXIT_APP_ID, 0, R.string.exit_application); return result; } @Override public boolean onMenuItemSelected(int featureId, MenuItem item) { switch(item.getItemId()) { case SIGN_UP_ID: Intent i = new Intent(LoggingIn.this, signingUp.class); startActivity(i); return true; case EXIT_APP_ID: return true; } return super.onMenuItemSelected(featureId, item); }
Quote:onCreateOptionsMenu (Menu menu) initializes the contents of the Activity's standard options menu. You should place your menu items in to menu. This is only called once, the first time the options menu is displayed. To update the menu every time it is displayed, see onPrepareOptionsMenu(Menu).
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)