0

i have a photo sharing apps which display bottom menu in all layout i have create one but is display when i press menu key i want menu which display when any activity start so how can i create general menu for all layout and no need to press menu key for display bottom menu bar android thanks

menu.xml
<?xml version="1.0" encoding="utf-8"?>

<menu xmlns:android="http://schemas.android.com/apk/res/android">

<item android:id="@+id/menu_bookmark"
      android:icon="@drawable/icon_bookmark"
      android:title="Bookmark" />

<item android:id="@+id/menu_share"
      android:icon="@drawable/icon_share"
      android:title="Share" />

<item android:id="@+id/menu_delete"
      android:icon="@drawable/icon_delete"
      android:title="Delete" /> 


</menu>

activity.java

@Override
public boolean onCreateOptionsMenu(Menu menu)
{
    MenuInflater menuInflater = getMenuInflater();
    menuInflater.inflate(R.layout.menu, menu);
    return true;
}
MIP TECH
  • 559
  • 2
  • 5
  • 9
  • FYI, if you're looking to use `include` and `merge` with an actual menu, you'll need, instead, to inflate multiple menu XML files, as described here: http://stackoverflow.com/questions/4337034/include-menu-in-menu-android – Joshua Pinter May 09 '14 at 02:10

1 Answers1

0

Instead of creating Menu you have to make a common custom xml layout for your menu and include it with your all activity's layout xml file. For this you can use <merge> and <include> tag of Android XML Layout.

Look at Layout Tricks: Merging Layouts

Layout Tricks: Creating Reusable UI Components

Update:

Now on your question, To open a Menu without pressing Menu Button, you can put this line in your onCreate() of Activity.

openOptionsMenu();

And to close:

closeOptionsMenu();

These both methods for Activity class, So if you are using it out-side of activity then use context of Activity and with this method.

user370305
  • 108,599
  • 23
  • 164
  • 151