android - 如何自定义 Google map 中信息窗口的 state_pressed 颜色?

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

我正在尝试自定义 Google map 中 InfoWindow 的 state_pressed 行为。通常当这个信息窗口被按下时,它会变成黄色。自定义 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 只是添加了一个简单的 drawable 并向其添加了一些文本,并使其可点击。可点击与否没有区别。

<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 语句(第一个为真,第二个为假),颜色会发生变化。但是只有未按下状态发生变化,按下状态仍然是黄色。

最佳答案

您可能想在这里为这个改进点赞:http://code.google.com/p/gmaps-api-issues/issues/detail?id=4783

关于android - 如何自定义 Google map 中信息窗口的 state_pressed 颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15531578/

相关文章:

android - 在哪里可以找到OAuth2.0的标识符和 secret , 'imaginary functions'是什么意思?

android - Android 上的路线 API

javascript - 将天气小部件嵌入到 Google map 的信息窗口中

android - 为什么在项目中使用不同的 Google API key ?

marker - 如何在地理编码器放置标记后创建信息窗口

javascript - 谷歌地图信息窗口位置

android - 带有按钮的 ListView,但只有按钮被选中,而不是列表

android - Unity GearVR 去掉 "requesting permission..."

java - 等待/通知 vs sleep /中断 vs ReentrantLock.Condition

android - 折线未完成到谷歌地图上的目的地