我刚刚将MapView从Activity的布局迁移到了DialogFragment。这是一次相当轻松的迁移:
活动上的按钮将启动对话框,设置地图所需的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中所有Dialog的标准灰色覆盖所覆盖:
而且这也不是API身份验证的问题,所有的map函数都能完美地工作。我该如何解决这个问题呢?
发布于 2015-06-14 01:50:13
这就是我如何解决我的小困境的:
我为对话框设置了一个主题,特别是mapDialogFragment.setStyle(DialogFragment.STYLE_NORMAL, android.R.style.Theme_Light_Panel);
并在布局中添加了一些顶部和底部填充。结果是:
非常感谢saurabh1489帮我找到了答案!
发布于 2018-06-05 03:14:26
DialogFragmentUbicacion nd= new DialogFragmentUbicacion(); nd.setStyle(android.support.v4.app.DialogFragment.STYLE_NORMAL,R.style.MyStyle);
nd.show(getSupportFragmentManager(),null);
https://stackoverflow.com/questions/30820947
复制相似问题