【问题标题】:How to customise the state_pressed colour of an infowindow in Google Maps?如何自定义谷歌地图中信息窗口的 state_pressed 颜色?
【发布时间】:2013-03-20 18:14:33
【问题描述】:

我正在尝试自定义 Google 地图中 InfoWindow 的 state_pressed 行为。通常,当按下此 InfoWindow 时,它会变为黄色。自定义 InfoWindows 也是如此。但我想把它改成另一种颜色,比如红色、橙色或蓝色。

所以我创建了一个非常简单的自定义信息窗口,如下所示:

class MyInfoWindowAdapter implements InfoWindowAdapter {
    private final View myContentsView;

    MyInfoWindowAdapter() {
        myContentsView = getLayoutInflater().inflate(R.layout.popup, null);
    }

    @Override
    public View getInfoContents(Marker marker) {
        return null;
    }

    @Override
    public View getInfoWindow(Marker marker) {
        return getLayoutInflater().inflate(R.layout.popup2, null);
    }
}

popup2 的 xml 只是添加了一个简单的可绘制对象,并在其中添加了一些文本,并使其可点击。可点击与否并不重要。

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:text="Test Popup"
    android:background="@drawable/info_window"
    android:clickable="true"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >
</TextView>

最后是drawable:

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="false">
        <shape android:shape="rectangle">
            <stroke android:width="1dp" android:color="@color/divider" />
            <solid android:color="@color/background_button" />
            <padding android:left="40dip"
                 android:top="10dip"
                 android:right="10dip"
                 android:bottom="40dp"/> 

        </shape>
    </item>
    <item android:state_pressed="true">
        <shape android:shape="rectangle">
            <stroke android:width="1dp" android:color="@color/divider" />
            <solid android:color="@color/background_button_active" />
            <padding android:left="40dip"
                 android:top="10dip"
                 android:right="10dip"
                 android:bottom="40dp"/> 

        </shape>
    </item>
</selector>

这里的选择器是我希望改变 state_pressed 颜色的,但它没有。但是,如果我切换 android.state_pressed 语句(第一个为真,第二个为假),则选择器本身会被执行,颜色确实会改变。但只有未按下状态发生变化,按下状态仍变为黄色。

【问题讨论】:

    标签: android google-maps-android-api-2 infowindow


    【解决方案1】:

    您可能想在此处投票支持此增强功能:http://code.google.com/p/gmaps-api-issues/issues/detail?id=4783

    【讨论】:

      【解决方案2】:

      简单地说“你不能”。

      因为根据文档“信息窗口不是实时视图,而是将视图呈现为地图上的图像。因此,您在视图上设置的任何侦听器都将被忽略,并且您无法区分点击事件视图的各个部分。建议您不要将交互式组件(例如按钮、复选框或文本输入)放置在自定义信息窗口中。"

      所以,简而言之,除了 "OnInfoWindowClickListener"

      之外,您无法处理 infowindow 上的任何事件

      更多信息请查看“https://developers.google.com/maps/documentation/android/marker”。

      【讨论】:

      • 我知道它只是一个图像 - 但是“压制”版本(黄色版本)本身也必须是一个图像,因此可以(将?)在创建时呈现 -时间也是如此。至少,这是我所希望的……显然,不是。
      猜你喜欢
      • 1970-01-01
      • 2013-05-20
      • 1970-01-01
      • 1970-01-01
      • 2011-04-21
      • 1970-01-01
      • 2014-08-28
      • 2020-05-29
      • 2013-01-06
      相关资源
      最近更新 更多