Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android MapFragment在DialogActivity中使用时会得到一个黑色覆盖_Android_Android Maps V2 - Fatal编程技术网

Android MapFragment在DialogActivity中使用时会得到一个黑色覆盖

Android MapFragment在DialogActivity中使用时会得到一个黑色覆盖,android,android-maps-v2,Android,Android Maps V2,我试图用@Android:style/Theme.DeviceDefault.Light.Dialog.NoActionBar主题在活动中显示Android地图v2 API的MapFragment。这个很好用。但是,贴图会得到一个黑色覆盖: 当我将主题更改为@android:style/theme.DeviceDefault.Light.NoActionBar时,地图显示如下: 这是我的xml布局文件: <?xml version="1.0" encoding="utf-8"?>

我试图用
@Android:style/Theme.DeviceDefault.Light.Dialog.NoActionBar
主题在
活动中显示
Android地图v2 API的
MapFragment
。这个很好用。但是,贴图会得到一个黑色覆盖:

当我将主题更改为
@android:style/theme.DeviceDefault.Light.NoActionBar
时,地图显示如下:

这是我的xml布局文件:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <fragment
        android:id="@+id/mapfragment"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        class="com.google.android.gms.maps.MapFragment" />

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="HELLO"
        android:textSize="@dimen/textsize_large" />

</LinearLayout>


这里发生了什么事?

我也遇到了同样的问题。经过研究,我发现了两个漏洞:

  • 在styles.xml中为主题添加此参数:
    false
坏的部分:它删除了活动后面的黑色覆盖层

  • 设置贴图对象顶部的z顺序:
    GoogleMapOptions googleMapsOptions=new GoogleMapOptions()
    googleMapsOptions.zOrderOnTop(真)
    MapFragment MapFragment=MapFragment.newInstance(谷歌地图选项);
不好的地方:地图在缩放控制和我的位置按钮上方

个人而言,我选择第一种解决方案。
希望这有帮助


对于
对话框片段

getDialog().getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
此外,可以在地图显示时动态取消对话框窗口的暗显,并在地图消失时将其暗显(例如,当您的对话框有多个页面时,其中一个页面是地图):


仍然只是另一种解决方法,而不是解决根本原因…

根据您在对话框中对贴图的用途,如果您不需要任何贴图控件,可以使用
liteMode
,在该模式中,只显示贴图的图像以及加载的任何位置。它没有z层覆盖问题

您可以将其添加到
MapView
布局xml中:

map:liteMode=“true”

这对我很有用,因为我不希望我的地图是交互式的


您可以在此处阅读谷歌文档:

只需将这一行添加到您的样式中即可

    <item name="android:backgroundDimEnabled">false</item>
false
这是我的风格:

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/dark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="android:backgroundDimEnabled">false</item>
    <item name="windowActionBar">false</item>
</style>

@颜色/原色
@颜色/深色
@颜色/颜色重音
假的
假的

也许它能帮助你:。虽然代码可能会回答这个问题,但最好解释一下它是如何工作的以及为什么要使用它。这个解决方案对于已经有暗显背景(不会干扰谷歌地图)的透明活动很有用,特别是当默认的
对话框片段
暗显背景没有用处时,我认为应该添加以下内容:
getWindow().setAttributes(params)顺便说一句,我使用的是中国的AMap,我想谷歌地图早就解决了这个问题,对吗?
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/dark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="android:backgroundDimEnabled">false</item>
    <item name="windowActionBar">false</item>
</style>