LWUIT 开发教程(17):Virtual Keyboard

LWUIT库支持一个轻量级的屏幕软键盘,如果你的手机没有QWERT键盘,可以打开屏幕软键盘以方便文字输入。

打开对软键盘的支持,是在Display.init() 之前调用VKBImplementationFactory.init();

VKBImplementationFactory.init();

//init the LWUIT display
Display.init(this);

//setting the application theme
try{
 Resources r=Resources.open("/LWUITtheme.res");
 UIManager.getInstance()
 .setThemeProps(r.getTheme
 (r.getThemeResourceNames()[0]));
}catch (Exception e){}


Form mainForm = new Form("TextField  Demo");

mainForm.setLayout(new BorderLayout());

TextField textfield=new TextField();
textfield.setText("This is a text field");

mainForm.addComponent(BorderLayout.CENTER, textfield);

mainForm.setTransitionOutAnimator(CommonTransitions.createFade(400));

mainForm.addCommand(new Command("Left soft key", 2));
mainForm.addCommand(new Command("Right Soft key", 2));

mainForm.show();

此后,当TextField需要输入时,软键盘会自动出现。