How to add a menu to MapActivity?
I've got an app using MapActivity.onCreate() to initialize the map and show it on screen. Now I would like to add a menu to my app. From what I've found out I can't add a menu f开发者_Go百科rom MapActivity and need to use Activity (correct me if I'm wrong).
Now I have no idea how to "initialize" the map from my Activity-class.
And how would I have to fix the views, will I wrap my activity-layout around my Map-layout?
MapActivity
extends a regular Android Activity
, so there's nothing irregular you should need to do to create a menu.
Just override the onCreateOptionsMenu
method, as shown in the developers' guide.
MapActivity extends Activity, so you should be able to add a menu.
MapActivity is a subclass of Activity, and thus you do it the same way as in any normal Activity (instructions here). I've been able to successfully create menus the same way in MapActivity as in a normal Activity.
Make sure that it doesn't extend from FragmentActivity
but from AppCompatActivity
!
If that's the case, the onCreateOptionsMenu
method will be called and you are able to overwrite it like this:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_main, menu); //"menu_main" is the XML-File in res
return super.onCreateOptionsMenu(menu);
}
精彩评论