- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用以下代码在我的 map 折线上设置红色:
PolylineOptions rectOptions = new PolylineOptions();
rectOptions.color(R.color.colorPrimary);
String[][] lineInformation = ((MyApplication)getApplication()).getLineInformation(line);
for (int i=0; i<lineInformation.length; i++){
rectOptions.add(new LatLng(Double.parseDouble(lineInformation[i][0]),Double.parseDouble(lineInformation[i][1])));
}
但它不起作用,它没有显示我的应用程序的红色主色,而是显示带有一些 alpha 的深色。
我遵循了官方指南:https://developers.google.com/maps/documentation/android-api/shapes
最佳答案
您的问题是由 颜色资源标识符 和颜色值 混淆引起的,两者都是 int
。
我们来看看the documentation for PolylineOptions.color()
:
public PolylineOptions color (int color)
Sets the color of the polyline as a 32-bit ARGB color. The default color is black (
0xff000000
).
由于文档指出输入应该是“32 位 ARGB 颜色”,因此您不能只传递颜色资源 ID;您必须首先手动将其解析为颜色值。
R.color.colorPrimary
是一个 int
具有一些自动生成的值,可能类似于 0x7f050042
。不幸的是,这可以解释为 ARGB 颜色,并且是部分透明的极深蓝色。因此,应用程序不会崩溃,您只会在折线上看到意想不到的颜色。
要获得正确的颜色,请使用 ContextCompat.getColor()
将您的颜色资源 ID 解析为颜色值,然后将颜色值传递给 color()
方法:
Context c = /* some context here */
int colorPrimary = ContextCompat.getColor(c, R.color.colorPrimary);
rectOptions.color(colorPrimary);
关于android - PolylineOptions .color() 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49097427/
我正在尝试使用以下代码在我的 map 折线上设置红色: PolylineOptions rectOptions = new PolylineOptions(); rectOptions.color(R
我使用谷歌地图方向开发了一个网站。我的折线配置如下: var lineSymbol = { path: 'M 1.5 1 L 1 0 L 1 2 M 0.5 1 L 1 0', fil
我在每个 onLocationChange 上获取纬度和经度,并制定如下路线: public void onLocationChanged(Location location) { Pol
我是一名优秀的程序员,十分优秀!