我正在尝试将 RGB 转换为 HEX,但保存 Hex 值的 EditText 未显示0
这是我的代码:
etHexVal = (EditText) findViewById(R.id.etHex);
if (etHexVal.length() == 6) { //has 000000
}
if (etHexVal.length() < 6) { //anything else
Toast.makeText(getApplicationContext(), "Please enter SIX characters/numbers combination", 2000).show();
}
etHexVal.addTextChangedListener(new TextWatcher() {
public void afterTextChanged(Editable s) {
String filtered_str = s.toString();
if (filtered_str.matches(".*[^A-F^0-9].*")) {
filtered_str = filtered_str.replaceAll("[^A-F^0-9]", "");
s.clear();
s.append(filtered_str);
Toast.makeText(getApplicationContext(), "Only A-F and 0-9 is allowed", 2000).show();
}
}
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
});
private int getColorFromSeekbars()
{
return Color.argb(255, redSeek.getProgress(), greenSeek.getProgress(), blueSeek.getProgress());
}
private String displayHexVal() {
String k = "" + redSeek.getProgress() + greenSeek.getProgress() + blueSeek.getProgress() + "";
Toast.makeText(getApplicationContext(), k, 2000).show();
String strColor = String.format("#%06X", 0xFFFFFF & Integer.valueOf(k));
return strColor;
}
我有三个搜索栏,如果红色搜索栏为 0,绿色搜索栏为 0,蓝色搜索栏为 146,我想在编辑文本中显示000092
,etHexVal
但它只显示00009
。如果 RED 为 0,GREEN 为 85,BLUE 为 146,则etHexVal
显示 014C9 而不是 #005592。这里出了什么问题?