Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: display menu across several activities

I have several activities in my app. I want my activities to have the same menuitem, except one. I was wondering if there is an easy way to put the menuitem in all selected activities instead of copying and pasting the menuitem for each single activity? Basically I want to share the menuitem with selected activities.

Thanks,

like image 272
user522559 Avatar asked Dec 28 '10 18:12

user522559


People also ask

What is used to navigate between activities in android?

Transitioning Between Activities in AndroidThe SecondActivity will contain a ConstraintLayout with a TextView label showing “Second Activity” and a Button with the text “Back to First Activity”.

How do we link two activities in android?

Intent i = new Intent(FromActivity. this, ToActivity. class); startActivity(i); In this case the Intent uses your current Activity as the Context in the first parameter, and the destination Activity in the second parameter.


1 Answers

create a class (say class A) which extends activity and then create all your other activities by extending this class. Now in A keep the common menu items stored in a vector and any specific menu action can be added for any particular activity. This way you avoid the trouble of copying and pasting the menu items in every activity

like image 158
pankajagarwal Avatar answered Oct 20 '22 10:10

pankajagarwal