. layoutConfig config = new LayoutConfig(LayoutConfig.MATCH_PARENT, LayoutConfig.MATCH_PARENT);
. myLayout.setLayoutConfig(config);
. myLayout.setOrientation(Component.VERTICAL);
. ShapeElement element = new ShapeElement();
. element.setRgbColor(new RgbColor(255, 255, 255));
. myLayout.setBackground(element);
. log = createText(“日志信息“);
. myLayout.addComponent(log);
. writeBtn = createBtn(“写入preferences数据“, new RgbColor(0, 0, 255), 1002);
. readBtn = createBtn(“读取preferences数据“, new RgbColor(0, 0, 255), 1003);
. addObserver = createBtn(“注册观察者“, new RgbColor(255, 0, 0), 1004);
. private Text createText(String title) {
. Text text = new Text(this);
. DirectionalLayout.LayoutConfig config = new DirectionalLayout.LayoutConfig(DirectionalLayout.LayoutConfig.MATCH_CONTENT, DirectionalLayout.LayoutConfig.MATCH_CONTENT);
. text.setLayoutConfig(config);
. text.setText(title);
. text.setTextSize(48);
. text.setTextColor(new Color(0xFF0000FF));
. return text;
. }
. private Button createBtn(String title, RgbColor color, int id) {
. Button btn = new Button(this);
. LayoutConfig configBtn = new LayoutConfig(500, 100);
. configBtn.topMargin = 30;
. btn.setLayoutConfig(configBtn);
. btn.setText(title);
. btn.setId(id);
. btn.setTextSize(48);
. btn.setTextColor(new Color(0xFFFFFFFF));
. ShapeElement elementBtn = new ShapeElement();
. elementBtn.setRgbColor(color);
. elementBtn.setCornerRadius(12);
. btn.setBackground(elementBtn);
. myLayout.addComponent(btn);
. return btn;
. }