如何自定义在谷歌地图信息窗口的STATE

如何自定义在谷歌地图信息窗口的STATE

本文介绍了如何自定义在谷歌地图信息窗口的STATE_ pressed颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图定义在谷歌地图信息窗口的STATE_ pressed行为。通常,当这个信息窗口为pressed,它变成黄色。这也是自定义信息窗口的情况。但我想这个改变到另一种颜色,如红色或橙色或蓝色。

I am trying to customise the state_pressed behaviour of an InfoWindow in Google Maps. Normally when this InfoWindow is pressed, it turns yellow. That's also the case with custom InfoWindows. But I want to change this to another colour, like red or orange or blue.

所以,我创建了一个非常简单的自定义信息窗口是这样的:

So I created a very simple custom InfoWindow like this:

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只是增加了一个简单的绘制,并添加文本的一点点吧,变成可点击。可点击与否并不有所作为。

The xml for popup2 just adds a simple drawable and adds a little bit of text to it, and made clickable. Clickable or not does not make a difference.

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

这里的选择是我希望将使STATE_ pressed颜色改变,但事实并非如此。选择器本身是建立在行动虽然,如果我切换 android.state_ pressed 语句(第一个真正的,第二假)的颜色是变化的。但是,只有在没有pressed状态发生变化时,pressed状态仍然得到黄色。

The selector here is what I hoped would make the state_pressed colour to change, but it doesn't. The selector itself is acted upon though, if I switch the android.state_pressed statements (first true, second false) the colour does change. But only the not pressed state changes, the pressed state still gets the yellow colour.

推荐答案

在简单地说你不能。

因为按照文件的信息窗口是不是一个实时视图,而该视图呈现为一个图像到地图上。这样一来,你在视图上设置的所有听众都被忽略,你可以点击事件之间的不区分。视图的各个部分建议您不要对交互式组件 - 如按钮,复选框或文本输入 - 。您的自定义信息窗口内的

because as per documentation "An info window is not a live View, rather the view is rendered as an image onto the map. As a result, any listeners you set on the view are disregarded and you cannot distinguish between click events on various parts of the view. You are advised not to place interactive components — such as buttons, checkboxes, or text inputs — within your custom info window."

所以,总之你无法处理比其他信息窗口的任何事件的OnInfoWindowClickListener

So, in short u can't handle any events on infowindow other than "OnInfoWindowClickListener"

有关更多的检查。

这篇关于如何自定义在谷歌地图信息窗口的STATE_ pressed颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 07:16