我在谷歌搜索了很多关于这个和Android文档的内容,直到现在我还没有找到办法做到这一点。是否有解决方案在地图片段上调用上下文菜单?
这是我的MapActivity的一部分:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_maps);
setUpMapIfNeeded();
View v = findViewById(R.id.map); // not sure about this part
registerForContextMenu(v);
}
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo info){
super.onCreateContextMenu(menu,v,info);
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu_contextual, menu);
}
public boolean onContextItemSelected(MenuItem item) {
switch (item.getItemId()){
case R.id.needHelp:
return true;
case R.id.giveHelp:
return true;
default:
return super.onContextItemSelected(item);
}
}
//this one is my Fragment Layout
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/map"
tools:context=".MapsActivity"
android:name="com.google.android.gms.maps.SupportMapFragment"/>