【发布时间】:2020-07-31 01:02:51
【问题描述】:
我在 Android 应用程序中有一个 Google 地图视图,并创建了一个自定义标记图标(来自 svg),如下所示:
用途
mMap.addMarker {
position(LatLng(mLastLocation.latitude, mLastLocation.longitude))
title("Path marker")
icon(bitmapDescriptorFromVector(this@DrivingActivity, R.drawable.ic_marker))
anchor(0.5F,0.5F)
flat(true)
}
方法
private fun bitmapDescriptorFromVector(context: Context, vectorResId: Int): BitmapDescriptor? {
return ContextCompat.getDrawable(context, vectorResId)?.run {
setBounds(0, 0, 44, 36)
val bitmap = Bitmap.createBitmap(44, 36, Bitmap.Config.ARGB_8888)
draw(Canvas(bitmap))
BitmapDescriptorFactory.fromBitmap(bitmap)
}
}
如何像在 ImageViews 中那样添加色调?目标是为多种目的重复使用相同的图像资源 - 只是颜色会有所不同。
【问题讨论】:
标签: android kotlin google-maps-markers