我已经实现了一些自定义字段,并希望保持与当前Blackberry主题一致的外观。因此,我希望字段的突出显示颜色与BB应用程序中使用的突出显示颜色一致。
我怎样才能得到这种颜色?
编辑:显然,no way可以从任何API获取这些颜色。那么有一种解决这些颜色的解决办法吗?
答案 0 :(得分:3)
我们可以做的是在某些自定义文本字段的drawFocus方法上测试颜色:
class TestField extends TextField {
TestThemeListener mListener;
public TestField(TestThemeListener listener) {
super(EDITABLE | FOCUSABLE);
setText("Hello this is a color test");
setSelection(0, true, 10);
mListener = listener;
}
protected void drawFocus(Graphics g, boolean on) {
drawHighlightRegion(g, HIGHLIGHT_FOCUS, true, 0, 0, 50, 20);
Bitmap bmp = new Bitmap(50, 20);
Display.screenshot(bmp, 0, 0, 50, 20);
int[] argbData = new int[1];
bmp.getARGB(argbData, 0, 1, 0, 0, 1, 1);
int focusColor = argbData[0];
drawHighlightRegion(g, HIGHLIGHT_SELECT, true, 50, 0, 50, 20);
Display.screenshot(bmp, 50, 0, 50, 20);
argbData = new int[1];
bmp.getARGB(argbData, 0, 1, 0, 0, 1, 1);
int selectionColor = argbData[0];
if (null != mListener) {
mListener.themeTested(focusColor, selectionColor);
mListener = null;
}
}
}
interface TestThemeListener {
void themeTested(int focusColor, int selectionColor);
}
并在屏幕上使用它:
class Scr extends MainScreen implements TestThemeListener {
LabelField mSelectionColorName;
LabelField mFocusColorName;
public Scr() {
add(new TestField(this));
}
public void themeTested(int focusColor, int selectionColor) {
add(new LabelField("Theme colors (AARRGGBB)"));
add(new LabelField("Focus : " + focusColor));
Bitmap bmpF = new Bitmap(100, 20);
Graphics gF = new Graphics(bmpF);
gF.setColor(focusColor);
gF.fillRect(0, 0, 100, 20);
add(new BitmapField(bmpF));
add(new LabelField("Selection : " + selectionColor));
Bitmap bmpS = new Bitmap(100, 20);
Graphics gS = new Graphics(bmpS);
gS.setColor(selectionColor);
gS.fillRect(0, 0, 100, 20);
add(new BitmapField(bmpS));
}
}
color test app screenshot http://img188.imageshack.us/img188/8943/830001.png
答案 1 :(得分:1)
这很好但是有问题。必须对应用程序进行签名,并向用户显示一个确认信息,例如“应用程序xxx想要拍摄屏幕截图。允许吗?”这可能会让用户烦恼。这是因为在设备类中使用安全API。
相反,请尝试从Graphics
创建新的Bitmap
,然后在其上绘制。
class TestField : extends Field {
int getHighlightColor() {
Bitmap image = new Bitmap(getWidth(), getHeight());
Graphics g = new Graphics(image).
drawHighlightRegion(g, Field.HIGHLIGHT_FOCUS, true, 0, 0, getWidth(), getHeight());
paint(
argbData = new int[1];
image.getARGB(argbData, 0, 1, 0, 0, 1, 1);
return argbData[0];
}
}