我想要一个用于输入数字的文本字段。我想让它成为中心。并希望用数字键盘允许它。
它在 BB OS 5 上运行良好,在使用 BB OS 6 / 7 / 7.1 时,我无法显示数字键盘。
以下是代码:
txtEventNumber = new RichTextField(RichTextField.TEXT_ALIGN_HCENTER) {
public void paint(Graphics graphics) {
super.paint(graphics);
int oldColor = Color.GRAY;
graphics.setBackgroundColor(Color.WHITE);
graphics.setColor(TEXT_COLOR);
Font font = this.getFont().derive(Font.EMBOSSED_EFFECT, 20);
this.setFont(font);
graphics.drawRoundRect(0, 0, getWidth(), getHeight(), 10, 10);
graphics.setColor(oldColor);
super.paint(graphics);
}
public int getPreferredHeight() {
return super.getPreferredHeight() + ADD_MARGIN;
}
protected void onFocus(int direction) {
if (Touchscreen.isSupported() && getScreen().getVirtualKeyboard() != null)
// Show keyboard
getScreen().getVirtualKeyboard().setVisibility(VirtualKeyboard.SHOW);
};
protected void onUnfocus() {
if (Touchscreen.isSupported() && getScreen().getVirtualKeyboard() != null)
// Hide keyboard
getScreen().getVirtualKeyboard().setVisibility(VirtualKeyboard.HIDE_FORCE);
};
};
txtEventNumber.setEditable(true);
// can enter only numeric digits
if (Touchscreen.isSupported())
// show numeric keypad
txtEventNumber.setFilter(TextFilter.get(TextFilter.DEFAULT_SMART_PHONE));
else
txtEventNumber.setFilter(TextFilter.get(TextFilter.REAL_NUMERIC));
txtEventNumber.setMargin(10, 10, 0, 10);