Making an android map menu to change map type

前端 未结 3 1271
野性不改
野性不改 2020-12-28 11:58

I have a map in my android app. By default it shows the satellite view, but I have turned it off to only show the road maps view. However, I am wondering how I would constru

3条回答
  •  醉话见心
    2020-12-28 12:35

    Just add this to your Activity:

      @Override
      public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.menu_items, menu);
            return true;
      }
    
      @Override
      public boolean onOptionsItemSelected(MenuItem item) {
         switch (item.getItemId()) {
           case R.id.item1 :
            //do what you like
           default :
             return super.onOptionsItemSelected(item);
         }
      }
    

    This should be in a separate xml file (maybe /res/menu/menu_items.xml)

    
        
        
    
    

提交回复
热议问题