我有以下阵列适配器-
public class ColorAttributeArrayAdapter extends ArrayAdapter<ProductAttributeModel> {
private List<ProductAttributeModel> titles;
private Context context;
public ColorAttributeArrayAdapter(@NonNull Context context, List<ProductAttributeModel> titles) {
super(context, R.layout.product_attribute_spinner_row_item, R.id.product_attribute_spinner_row_item_textview, titles);
this.titles = titles;
this.context = context;
}
@NonNull
@Override
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
View listItem = convertView;
if (listItem == null) {
listItem = LayoutInflater.from(context).inflate(R.layout.product_attribute_spinner_row_item, parent, false);
}
String currentString = titles.get(position).getAttributeValue();
//Setting the image color
ImageView imageView = listItem.findViewById(R.id.product_attribute_spinner_row_item_image_view);
Map<String, String> htmlStandardColorMap = ColorUtil.getHtmlStandardColorMap();
if (htmlStandardColorMap.containsKey(StringUtils.uncapitizeString(currentString))) {
imageView.getLayoutParams().height = 60;
imageView.getLayoutParams().width = 60;
imageView.setBackgroundColor(Color.parseColor(htmlStandardColorMap.get(StringUtils.uncapitizeString(currentString))));
} else {
String colorURL = COLORS_API.concat(Uri.encode(currentString, "UTF-8"));
Picasso.get().load(colorURL).resize(90, 90).into(imageView);
}
TextView value = listItem.findViewById(R.id.product_attribute_spinner_row_item_textview);
value.setText(currentString);
// }
return listItem;
}
@Override
public View getDropDownView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
return getView(position, convertView, parent);
}
}
这里是ColorUtil类-
public class ColorUtil {
public static Map<String, String> getHtmlStandardColorMap() {
Map<String, String> colorMap = new HashMap<>();
colorMap.put("aliceblue", "#F0F8FFFF");
colorMap.put("antiquewhite", "#FAEBD7FF");
colorMap.put("aqua", "#00FFFFFF");
colorMap.put("aquamarine", "#7FFFD4FF");
colorMap.put("azure", "#F0FFFFFF");
colorMap.put("beige", "#F5F5DCFF");
colorMap.put("bisque", "#F0F8FF");
colorMap.put("black", "#000000FF");
colorMap.put("blanchedalmond", "#FFEBCDFF");
colorMap.put("blue", "#0000FFFF");
colorMap.put("blueviolet", "#8A2BE2FF");
colorMap.put("brown", "#A52A2AFF");
colorMap.put("burlywood", "#F0F8FF");
colorMap.put("cadetblue", "#5F9EA0FF");
colorMap.put("chartreuse", "#7FFF00FF");
colorMap.put("chocolate", "#D2691EFF");
colorMap.put("coral", "#FF7F50FF");
colorMap.put("cornflowerblue", "#6495EDFF");
colorMap.put("cornsilk", "#FFF8DCFF");
colorMap.put("crimson", "#DC143CFF");
colorMap.put("cyan", "#00FFFFFF");
colorMap.put("darkblue", "#00008BFF");
colorMap.put("darkcyan", "#008B8BFF");
colorMap.put("darkgoldenrod", "#B8860BFF");
colorMap.put("darkgray", "#A9A9A9FF");
colorMap.put("darkgrey", "#A9A9A9FF");
colorMap.put("darkgreen", "#006400FF");
colorMap.put("darkkhaki", "#BDB76BFF");
colorMap.put("darkmagenta", "#8B008BFF");
colorMap.put("darkolivegreen", "#556B2FFF");
colorMap.put("darkorange", "#FF8C00FF");
colorMap.put("darkorchid", "#9932CCFF");
colorMap.put("darkred", "#8B0000FF");
colorMap.put("darksalmon", "#E9967AFF");
colorMap.put("darkseagreen", "#8FBC8FFF");
colorMap.put("darkslateblue", "#483D8BFF");
colorMap.put("darkslategray", "#2F4F4FFF");
colorMap.put("darkslategrey", "#2F4F4FFF");
colorMap.put("darkturquoise", "#00CED1FF");
colorMap.put("darkviolet", "#9400D3FF");
colorMap.put("deeppink", "#FF1493FF");
colorMap.put("deepskyblue", "#00BFFFFF");
colorMap.put("dimgray", "#696969FF");
colorMap.put("dimgrey", "#696969FF");
colorMap.put("dodgerblue", "#1E90FFFF");
colorMap.put("firebrick", "#B22222FF");
colorMap.put("floralwhite", "#FFFAF0FF");
colorMap.put("forestgreen", "#228B22FF");
colorMap.put("fuchsia", "#FF00FFFF");
colorMap.put("gainsboro", "#DCDCDCFF");
colorMap.put("ghostwhite", "#F8F8FFFF");
colorMap.put("gold", "#FFD700FF");
colorMap.put("goldenrod", "#DAA520FF");
colorMap.put("gray", "#808080FF");
colorMap.put("grey", "#808080FF");
colorMap.put("green", "#008000FF");
colorMap.put("greenyellow", "#ADFF2FFF");
colorMap.put("honeydew", "#F0FFF0FF");
colorMap.put("hotpink", "#FF69B4FF");
colorMap.put("indianred", "#CD5C5CFF");
colorMap.put("indigo", "#4B0082FF");
colorMap.put("ivory", "#FFFFF0FF");
colorMap.put("khaki", "#F0E68CFF");
colorMap.put("lavender", "#E6E6FAFF");
colorMap.put("lavenderblush", "#FFF0F5FF");
colorMap.put("lawngreen", "#7CFC00FF");
colorMap.put("lemonchiffon", "#FFFACDFF");
colorMap.put("lightblue", "#ADD8E6FF");
colorMap.put("lightcoral", "#F08080FF");
colorMap.put("lightcyan", "#E0FFFFFF");
colorMap.put("lightgoldenrodyellow", "#FAFAD2FF");
colorMap.put("lightgray", "#D3D3D3FF");
colorMap.put("lightgrey", "#D3D3D3FF");
colorMap.put("lightgreen", "#90EE90FF");
colorMap.put("lightpink", "#FFB6C1FF");
colorMap.put("lightsalmon", "#FFA07AFF");
colorMap.put("lightseagreen", "#20B2AAFF");
colorMap.put("lightskyblue", "#87CEFAFF");
colorMap.put("lightslategray", "#778899FF");
colorMap.put("lightslategrey", "#778899FF");
colorMap.put("lightsteelblue", "#B0C4DEFF");
colorMap.put("lightyellow", "#FFFFE0FF");
colorMap.put("lime", "#00FF00FF");
colorMap.put("limegreen", "#32CD32FF");
colorMap.put("linen", "#FAF0E6FF");
colorMap.put("magenta", "#FF00FFFF");
colorMap.put("maroon", "#800000FF");
colorMap.put("mediumaquamarine", "#66CDAAFF");
colorMap.put("mediumblue", "#0000CDFF");
colorMap.put("mediumorchid", "#BA55D3FF");
colorMap.put("mediumpurple", "#9370D8FF");
colorMap.put("mediumseagreen", "#3CB371FF");
colorMap.put("mediumslateblue", "#7B68EEFF");
colorMap.put("mediumspringgreen", "#00FA9AFF");
colorMap.put("mediumturquoise", "#48D1CCFF");
colorMap.put("mediumvioletred", "#C71585FF");
colorMap.put("midnightblue", "#191970FF");
colorMap.put("mintcream", "#F5FFFAFF");
colorMap.put("mistyrose", "#FFE4E1FF");
colorMap.put("moccasin", "#FFE4B5FF");
colorMap.put("navajowhite", "#FFDEADFF");
colorMap.put("navy", "#000080FF");
colorMap.put("oldlace", "#FDF5E6FF");
colorMap.put("olive", "#808000FF");
colorMap.put("olivedrab", "#6B8E23FF");
colorMap.put("orange", "#FFA500FF");
colorMap.put("orangered", "#FF4500FF");
colorMap.put("orchid", "#DA70D6FF");
colorMap.put("palegoldenrod", "#EEE8AAFF");
colorMap.put("palegreen", "#98FB98FF");
colorMap.put("paleturquoise", "#AFEEEEFF");
colorMap.put("palevioletred", "#D87093FF");
colorMap.put("papayawhip", "#FFEFD5FF");
colorMap.put("peachpuff", "#FFDAB9FF");
colorMap.put("peru", "#CD853FFF");
colorMap.put("pink", "#FFC0CBFF");
colorMap.put("plum", "#DDA0DDFF");
colorMap.put("powderblue", "#B0E0E6FF");
colorMap.put("purple", "#800080FF");
colorMap.put("rebeccapurple", "#663399FF");
colorMap.put("red", "#FF0000FF");
colorMap.put("rosybrown", "#BC8F8FFF");
colorMap.put("royalblue", "#4169E1FF");
colorMap.put("saddlebrown", "#8B4513FF");
colorMap.put("salmon", "#FA8072FF");
colorMap.put("sandybrown", "#F4A460FF");
colorMap.put("seagreen", "#2E8B57FF");
colorMap.put("seashell", "#FFF5EEFF");
colorMap.put("sienna", "#A0522DFF");
colorMap.put("silver", "#C0C0C0FF");
colorMap.put("skyblue", "#87CEEBFF");
colorMap.put("slateblue", "#6A5ACDFF");
colorMap.put("slategray", "#708090FF");
colorMap.put("slategrey", "#708090FF");
colorMap.put("snow", "#FFFAFAFF");
colorMap.put("springgreen", "#00FF7FFF");
colorMap.put("steelblue", "#4682B4FF");
colorMap.put("tan", "#D2B48CFF");
colorMap.put("teal", "#008080FF");
colorMap.put("thistle", "#D8BFD8FF");
colorMap.put("tomato", "#FF6347FF");
colorMap.put("turquoise", "#40E0D0FF");
colorMap.put("violet", "#EE82EEFF");
colorMap.put("wheat", "#F5DEB3FF");
colorMap.put("white", "#FFFFFFFF");
colorMap.put("whitesmoke", "#F5F5F5FF");
colorMap.put("yellow", "#FFFF00FF");
colorMap.put("yellowgreen", "#9ACD32FF");
return colorMap;
}
}
问题是,当currentString
位于地图内部时,我在错误的位置上获得了颜色,有时甚至根本没有获得任何颜色,例如我的地图上存在的黄色-
为什么会这样?某些东西在搅乱我的图像顺序,并阻止出现黄色
已解决-我的颜色映射最后包含不必要的FF
,导致颜色变得与我期望的不同。