java-如何在android中将RGB转换为十六进制颜色?
作者:互联网
这个问题已经在这里有了答案: > Convert RGBA values to hex color code 2个
如何将ARGB(255 0 255 0)颜色转换为十六进制颜色.我的数据库中有ARGB颜色,我使用JSON格式的Web服务进行检索.我想在文本字段TAG_DIFF_P(R.id.l7)中添加颜色
here it my code, how to add color in background in the text field
try {
JSONObject json1 = jParser.getJSONFromUrl(myUrl);
// Getting Array of Contacts
JSONArray list = json1.getJSONArray(TAG_JSONDataResult);
// looping through All Contacts
for(int i = 0; i < list.length(); i++){
JSONObject c = list.getJSONObject(i);
String GRPNAME = c.getString(TAG_GRPNAME);
String QTY = c.getString(TAG_QNT);
String BUDGET = c.getString(TAG_BUDGET);
String STOCK = c.getString(TAG_STOCK);
String DIFF = c.getString(TAG_DIFF);
String DIFF_P = c.getString(TAG_DIFF_P);
String COLOR = c.getString(TAG_COLOR);
// creating new HashMap
HashMap<String, String> map = new HashMap<String, String>();
// adding each child node to HashMap key => value
map.put(TAG_GRPNAME, GRPNAME);
map.put(TAG_QNT, QTY);
map.put(TAG_BUDGET, BUDGET);
map.put(TAG_STOCK, STOCK);
map.put(TAG_DIFF, DIFF);
map.put(TAG_DIFF_P, DIFF_P);
// adding HashList to ArrayList
contactList.add(map);
}
} catch (JSONException e) {
e.printStackTrace();
}
/**
* Updating parsed JSON data into ListView
* */
ListAdapter adapter = new SimpleAdapter(this, contactList,
R.layout.list_item,
new String[] { TAG_GRPNAME, TAG_QNT, TAG_BUDGET, TAG_STOCK, TAG_DIFF, TAG_DIFF_P, },
new int[] {
R.id.l2, R.id.l3, R.id.l4, R.id.l5, R.id.l6, R.id.l7});
lv2.setAdapter(adapter);
}
解决方法:
我认为您的json应该具有String形式.如果是这样,您可以尝试一下
String hex = String.format("#%02x%02x%02x", r, g,b);
标签:colors,hex,argb,java,android 来源: https://codeday.me/bug/20191030/1969437.html