我正在尝试自定义 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
语句(第一个为真,第二个为假),颜色会发生变化。但是只有未按下状态发生变化,按下状态仍然是黄色。
最佳答案
关于android - 如何自定义 Google map 中信息窗口的 state_pressed 颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15531578/