Android 如何在谷歌地图中定制信息窗口的状态颜色?

Android 如何在谷歌地图中定制信息窗口的状态颜色?,android,google-maps-android-api-2,infowindow,Android,Google Maps Android Api 2,Infowindow,我试图在谷歌地图中定制信息窗口的状态行为。通常,当按下此信息窗口时,它会变为黄色。自定义信息窗口也是如此。但我想把它换成另一种颜色,比如红色、橙色或蓝色 因此,我创建了一个非常简单的自定义信息窗口,如下所示: class MyInfoWindowAdapter implements InfoWindowAdapter { private final View myContentsView; MyInfoWindowAdapter() { myContentsVi

我试图在谷歌地图中定制信息窗口的状态行为。通常,当按下此信息窗口时,它会变为黄色。自定义信息窗口也是如此。但我想把它换成另一种颜色,比如红色、橙色或蓝色

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

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>

最后是可绘制的:

<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>

我希望这里的选择器能使状态改变,但事实并非如此。但是,如果我切换android.state\u pressed语句(第一个为真,第二个为假),则选择器本身会起作用,颜色会发生变化。但只有未按下的状态发生变化,按下的状态仍然是黄色。

简单地说就是“你不能”

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

因此,简而言之,除了“OnInfoWindowClickListener”


要了解更多信息,请参见“”。

您可能想在此处升级此增强功能:

我知道它仅仅是一个图像-但是“按下”版本(黄色版本)本身也必须是一个图像,因此也可以(将?)在创建时渲染。至少,这是我希望的…显然不是。