我在表单中有TextField,当它聚焦时,会出现一个键盘。现在如果我用这个键盘触摸命令,屏幕高度会降低。 我根据屏幕高度调整了一些填充。因此键盘会影响调整。如果我再次使用textField转到表单并在没有键盘的情况下触摸图标,则调整就可以了。怎么解决?
以表格
搜索文本字段Container searchContainer = new Container(new BoxLayout(BoxLayout.Y_AXIS));
f.add(searchContainer);
searchTextFieldGroup = new TextField();
searchContainer.add(searchTextFieldGroup);
searchTextFieldGroup.setHint("SEARCH TABLES");
searchTextFieldGroup.setUIID("tableSearchTextField");
searchTextFieldGroup.getAllStyles().setFont(Font.createSystemFont(Font.FACE_SYSTEM, Font.STYLE_ITALIC, Font.SIZE_SMALL));
searchTextFieldGroup.getAllStyles().setBgTransparency(0);
searchTextFieldGroup.getAllStyles().setMargin(2, 2, 2, 2);
searchTextFieldGroup.getAllStyles().setPadding(5, 5, 5, 0);
searchTextFieldGroup.getHintLabel().getAllStyles().setFont(Font.createSystemFont(Font.FACE_SYSTEM, Font.STYLE_ITALIC, Font.SIZE_SMALL));
searchTextFieldGroup.getHintLabel().getAllStyles().setFgColor(0xcccccc);
如果以上述形式打开或关闭键盘,屏幕高度会发生变化的主窗体
screenWidth = Display.getInstance().getDisplayWidth();
screenHeight = Display.getInstance().getDisplayHeight();
Container menuContainer;
(mainContainer code......)
int excessHeight = Math.max(screenHeight - t.getPreferredH() - menuContainer.getPreferredH(), 0);
int excessWidth = Math.max(screenWidth - menuContainer.getPreferredW(), 0);
menuContainer.getAllStyles().setPadding(Component.TOP, excessHeight / 2);
menuContainer.getAllStyles().setPadding(Component.BOTTOM, excessHeight / 2);
menuContainer.getAllStyles().setPadding(Component.LEFT, excessWidth / 2);
menuContainer.getAllStyles().setPadding(Component.RIGHT, (excessWidth / 2));
f.revalidate
返回btn点击键盘关闭.............支持键盘
如何添加设备键盘取消的高度?
f.addSizeChangedListener(e -> {
screenWidth = Display.getInstance().getDisplayWidth();
screenHeight = Display.getInstance().getDisplayHeight();
int excessHeight1 = Math.max(screenHeight - t.getPreferredH() - menuContainer.getPreferredH(), 0);
int excessWidth1 = Math.max(screenWidth - menuContainer.getPreferredW(), 0);
menuContainer.getAllStyles().setPadding(Component.TOP, excessHeight / 2);
menuContainer.getAllStyles().setPadding(Component.BOTTOM, excessHeight / 2);
menuContainer.getAllStyles().setPadding(Component.LEFT, excessWidth / 2);
menuContainer.getAllStyles().setPadding(Component.RIGHT, (excessWidth / 2));
//Dialog.show("size change", "width " + screenWidth + " height " + screenHeight, "ok", null);
});
方向侦听器由sizeChangeListener取消。如何解决?
f.addOrientationListener(new ActionListener() {
public void actionPerformed(ActionEvent ev) {
if (Display.getInstance().isPortrait()) {
screenWidth = Display.getInstance().getDisplayWidth();
screenHeight = Display.getInstance().getDisplayHeight();
menuContainer.getAllStyles().setPadding(0, 0, 0, 0);
menuContainer.getAllStyles().setMargin(0, 0, 0, 0);
int excessHeight = Math.max(screenHeight - t.getPreferredH() - menuContainer.getPreferredH(), 0);
int excessWidth = Math.max(f.getWidth() - menuContainer.getPreferredW(), 0);
menuContainer.getAllStyles().setPadding(Component.TOP, excessHeight / 2);
menuContainer.getAllStyles().setPadding(Component.BOTTOM, excessHeight / 2);
menuContainer.getAllStyles().setPadding(Component.LEFT, excessWidth / 2);
menuContainer.getAllStyles().setPadding(Component.RIGHT, (excessWidth / 2));
} else if (!Display.getInstance().isPortrait()) {
screenWidth = Display.getInstance().getDisplayWidth();
screenHeight = Display.getInstance().getDisplayHeight();
menuContainer.getAllStyles().setPadding(0, 0, 0, 0);
menuContainer.getAllStyles().setMargin(0, 0, 0, 0);
int excessHeight = Math.max(screenHeight - t.getPreferredH() - menuContainer.getPreferredH(), 0);
int excessWidth = Math.max(f.getWidth() - menuContainer.getPreferredW(), 0);
menuContainer.getAllStyles().setPadding(Component.TOP, excessHeight / 2);
menuContainer.getAllStyles().setPadding(Component.BOTTOM, excessHeight / 2);
menuContainer.getAllStyles().setPadding(Component.LEFT, excessWidth / 2);
menuContainer.getAllStyles().setPadding(Component.RIGHT, (excessWidth / 2) - 5);
f.revalidate();
}
}
});
答案 0 :(得分:1)
键盘打开时,很可能会改变大小,excessHeight
的值很小。
在Form sizeChanged()子句中放入相同的代码(第二个块)。