I am creating am android application which has 4 different activities all having a common menu. To show menu in all activities generally I need to add this code in every files.
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu, menu);
return true;
}
Is there anyway that I can add this code in one single file & include to all activities?
Thanks in advance.
Create one Main Activity
write your menu code in that activity and then extend
other activities with Main Activity..
public MainActivity extends Activity
{
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
return false;
}
}
And some TempActivity
public TempActivity extend MainActivity
{
/......
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With