Java 在谷歌地图中为“我的位置”按钮设置自定义视图
我正在使用谷歌地图Android API v2,我需要一种方法来更改“我的位置”按钮的视图(图标、颜色等) 现在我可以改变它的位置,但我需要一种方法来进行完全定制。 有人能帮我吗?我想你可以看到“我的位置”按钮视图,代码如下:Java 在谷歌地图中为“我的位置”按钮设置自定义视图,java,android,xml,google-maps,Java,Android,Xml,Google Maps,我正在使用谷歌地图Android API v2,我需要一种方法来更改“我的位置”按钮的视图(图标、颜色等) 现在我可以改变它的位置,但我需要一种方法来进行完全定制。 有人能帮我吗?我想你可以看到“我的位置”按钮视图,代码如下: View locationButton = ((View) mapView.findViewById(Integer.parseInt("1")).getParent()).findViewById(Integer.parseInt("2")); “位置”按钮实际上是一
View locationButton = ((View) mapView.findViewById(Integer.parseInt("1")).getParent()).findViewById(Integer.parseInt("2"));
“位置”按钮实际上是一个图像视图。您应该首先检索与地图关联的片段视图:
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
接下来,您应该从片段中获取位置视图引用:
ImageView locationButton = (ImageView) mapFragment.getView().findViewById(2);
然后将其图像更改为您想要的任何内容。e、 g
locationButton.setImageResource(R.drawable.icon_location);
希望有帮助。我使用
标记而不是Id
获取地图我的位置的默认ImageView
,以防止类型Id的预期资源lint警告-
ImageView imageView = ((ImageView)mapFragment.getView().findViewWithTag("GoogleMapMyLocationButton"));
然后,您可以操作图像视图
imageView.setImageResource(R.drawable.icon_custom_location);
awesome还定位按钮。setBackgroundResource它也在工作