Android Google 片段对话框中的地图被对话框自身的灰色覆盖层覆盖
Android Google Map in FragmentDialog being overlayed by the Dialog's own gray overlay
我刚刚将 MapView 从 Activity 的布局迁移到 DialogFragment。这是一个非常轻松的迁移:
activity 上的按钮启动对话框,设置 LatLng
地图要求:
case R.id.btn_open_map:
android.support.v4.app.FragmentManager fragmentManager
= getSupportFragmentManager();
DirectionsMapDialogFragment mapDialogFragment = new DirectionsMapDialogFragment();
mapDialogFragment.setLatLng(mLatLng);
mapDialogFragment.setRetainInstance(false);
mapDialogFragment.show(fragmentManager, "fragmentName");
break;
片段本身都是非常标准的代码。但是我确实使用自定义布局,因为我有一个按钮覆盖在启动 GoogleMaps 应用程序的地图上:
<FrameLayout
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:clickable="true"
tools:context="com.alexrafa.meetmi.fragments.DirectionsMapFragment"
android:background="@android:color/transparent">
<com.google.android.gms.maps.MapView
android:id="@+id/mv_location_map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"
android:apiKey="APIKEY"
/>
<ImageButton
android:layout_width="39dp"
android:layout_height="39dp"
android:src="@drawable/ic_directions_grey600_24dp"
android:id="@+id/btn_directions"
android:background="@drawable/background_map_button"
android:layout_gravity="top|center|right"
android:layout_marginRight="11dp"
android:layout_marginTop="60dp"
android:contentDescription="@string/btn_get_map_directions" />
</FrameLayout>
请注意我是如何尝试在 FrameLayout
中将背景设置为透明的。我这样做是因为我的地图似乎被所有对话框在 Android:
中的标准灰色覆盖层覆盖
而且这不是 API 身份验证问题,地图的所有功能都运行良好。我该如何解决这个问题?
这就是我最终解决我的小困境的方式:
我为对话框设置了一个主题,特别是 mapDialogFragment.setStyle(DialogFragment.STYLE_NORMAL, android.R.style.Theme_Light_Panel);
并在布局中添加了一些顶部和底部填充。结果:
感谢 saurabh1489 帮我找到答案!
DialogFragmentUbicacion nd= new DialogFragmentUbicacion(); nd.setStyle(android.support.v4.app.DialogFragment.STYLE_NORMAL,R.style.MyStyle);
nd.show(getSupportFragmentManager(),null);
我刚刚将 MapView 从 Activity 的布局迁移到 DialogFragment。这是一个非常轻松的迁移:
activity 上的按钮启动对话框,设置 LatLng
地图要求:
case R.id.btn_open_map:
android.support.v4.app.FragmentManager fragmentManager
= getSupportFragmentManager();
DirectionsMapDialogFragment mapDialogFragment = new DirectionsMapDialogFragment();
mapDialogFragment.setLatLng(mLatLng);
mapDialogFragment.setRetainInstance(false);
mapDialogFragment.show(fragmentManager, "fragmentName");
break;
片段本身都是非常标准的代码。但是我确实使用自定义布局,因为我有一个按钮覆盖在启动 GoogleMaps 应用程序的地图上:
<FrameLayout
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:clickable="true"
tools:context="com.alexrafa.meetmi.fragments.DirectionsMapFragment"
android:background="@android:color/transparent">
<com.google.android.gms.maps.MapView
android:id="@+id/mv_location_map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"
android:apiKey="APIKEY"
/>
<ImageButton
android:layout_width="39dp"
android:layout_height="39dp"
android:src="@drawable/ic_directions_grey600_24dp"
android:id="@+id/btn_directions"
android:background="@drawable/background_map_button"
android:layout_gravity="top|center|right"
android:layout_marginRight="11dp"
android:layout_marginTop="60dp"
android:contentDescription="@string/btn_get_map_directions" />
</FrameLayout>
请注意我是如何尝试在 FrameLayout
中将背景设置为透明的。我这样做是因为我的地图似乎被所有对话框在 Android:
而且这不是 API 身份验证问题,地图的所有功能都运行良好。我该如何解决这个问题?
这就是我最终解决我的小困境的方式:
我为对话框设置了一个主题,特别是 mapDialogFragment.setStyle(DialogFragment.STYLE_NORMAL, android.R.style.Theme_Light_Panel);
并在布局中添加了一些顶部和底部填充。结果:
感谢 saurabh1489 帮我找到答案!
DialogFragmentUbicacion nd= new DialogFragmentUbicacion(); nd.setStyle(android.support.v4.app.DialogFragment.STYLE_NORMAL,R.style.MyStyle);
nd.show(getSupportFragmentManager(),null);