我想在Google Maps中自定义InfoWindow的state_pressed行为。通常当这个InfoWindow被按下时,它变成黄色。自定义InfoWindows也是如此。但我想将其改为另一种颜色,如红色,橙色或蓝色。如何在Google地图中自定义infowindow的state_pressed颜色?
所以我创建了一个非常简单的自定义信息窗口是这样的:
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>
这里的选择是什么,我希望这将让state_pressed颜色改变,但事实并非如此。尽管选择器本身的作用,如果我切换android.state_pressed
声明(第一个真,第二个假)颜色确实改变。但只有未按下的状态才会变化,按下的状态仍然会变成黄色。
我知道它是一个单纯的形象 - 但“按下”版本(黄版)必须在自身的形象,也正因为如此能(将?)在创建时也被渲染。至少,这正是我所希望的......显然,不是。 – Wouter 2013-03-21 00:22:49