|
|
AIWROKÈí¼þÆ»¹ûUI°´Å¥Button·½·¨Ê¾Àý
- // Button×ÛºÏʾÀý - È«ÃæÕ¹Ê¾ButtonµÄ¸÷ÖÖÓ÷¨ºÍÑùʽ
- // // 🍎½»Á÷QQȺ711841924Ⱥһ£¬Æ»¹ûÄÚ²âȺ£º528816639
- // ´´½¨TabView
- var tab = new TabView();
- // ÉèÖÃTab±êÌâ
- var titles = ["ButtonʾÀý"];
- tab.setTitles(titles);
- // ´´½¨Ö÷½çÃæ
- var mainView = new Vertical();
- mainView.setBackgroundColor(245, 245, 245);
- mainView.setSpacing(20);
- // Ìí¼Ó±êÌâ
- var titleLabel = new Label();
- titleLabel.setText("Button×ÛºÏʾÀý");
- titleLabel.setTextColor(50, 100, 150);
- titleLabel.setFontSize(24);
- mainView.addView(titleLabel);
- // Ìí¼Ó»ù±¾°´Å¥Ê¾Àý
- addSection(mainView, "»ù±¾°´Å¥Ê¾Àý");
- addBasicButtonExample(mainView);
- // Ìí¼Ó²ÊÉ«°´Å¥Ê¾Àý
- addSection(mainView, "²ÊÉ«°´Å¥Ê¾Àý");
- addColorButtonExample(mainView);
- // Ìí¼Ó½»»¥°´Å¥Ê¾Àý
- addSection(mainView, "½»»¥°´Å¥Ê¾Àý");
- addInteractiveButtonExample(mainView);
- // Ìí¼Ó״̬°´Å¥Ê¾Àý
- addSection(mainView, "״̬°´Å¥Ê¾Àý");
- addStateButtonExample(mainView);
- // Ìí¼Ó²¼¾Ö°´Å¥Ê¾Àý
- addSection(mainView, "²¼¾Ö°´Å¥Ê¾Àý");
- addLayoutButtonExample(mainView);
- // Ìí¼Ó¸ß¼¶°´Å¥Ê¾Àý
- addSection(mainView, "¸ß¼¶°´Å¥Ê¾Àý");
- addAdvancedButtonExample(mainView);
- // ÏÔʾÖ÷½çÃæ
- tab.show(() => {
- printl("ButtonʾÀý½çÃæÒѼÓÔØÍê³É");
- tab.addView(0, mainView);
- });
- // Ìí¼Ó section ±êÌâ
- function addSection(container, title) {
- var sectionLabel = new Label();
- sectionLabel.setText(title);
- sectionLabel.setTextColor(80, 80, 80);
- sectionLabel.setFontSize(18);
- // Ìí¼Ó¼ä¾à±êÇ©×÷ÎªÌæ´ú
- var spacing = new Label();
- spacing.setHeight(20);
- container.addView(spacing);
- container.addView(sectionLabel);
- var bottomSpacing = new Label();
- bottomSpacing.setHeight(10);
- container.addView(bottomSpacing);
- }
- // »ù±¾°´Å¥Ê¾Àý
- function addBasicButtonExample(container) {
- var buttonContainer = new Horizontal();
- buttonContainer.setSpacing(20);
-
- // »ù±¾°´Å¥
- var basicBtn = new Button();
- basicBtn.setText("»ù±¾°´Å¥");
- basicBtn.setWidth(120);
- basicBtn.setHeight(40);
- basicBtn.onClick(() => {
- printl("»ù±¾°´Å¥±»µã»÷");
- showToast("»ù±¾°´Å¥±»µã»÷");
- });
- buttonContainer.addView(basicBtn);
-
- // »ñÈ¡°´Å¥Îı¾
- var getTextBtn = new Button();
- getTextBtn.setText("»ñÈ¡Îı¾");
- getTextBtn.setWidth(120);
- getTextBtn.setHeight(40);
- getTextBtn.onClick(() => {
- var text = getTextBtn.getText();
- printl("°´Å¥Îı¾: " + text);
- showToast("°´Å¥Îı¾: " + text);
- });
- buttonContainer.addView(getTextBtn);
-
- container.addView(buttonContainer);
- }
- // ²ÊÉ«°´Å¥Ê¾Àý
- function addColorButtonExample(container) {
- var buttonContainer = new Horizontal();
- buttonContainer.setSpacing(15);
-
- // À¶É«°´Å¥
- var blueBtn = new Button();
- blueBtn.setText("À¶É«°´Å¥");
- blueBtn.setColor(50, 100, 150);
- blueBtn.setTextColor(255, 255, 255);
- blueBtn.setWidth(100);
- blueBtn.setHeight(40);
- blueBtn.onClick(() => {
- showToast("À¶É«°´Å¥±»µã»÷");
- });
- buttonContainer.addView(blueBtn);
-
- // ºìÉ«°´Å¥
- var redBtn = new Button();
- redBtn.setText("ºìÉ«°´Å¥");
- redBtn.setColor(200, 50, 50);
- redBtn.setTextColor(255, 255, 255);
- redBtn.setWidth(100);
- redBtn.setHeight(40);
- redBtn.onClick(() => {
- showToast("ºìÉ«°´Å¥±»µã»÷");
- });
- buttonContainer.addView(redBtn);
-
- // ÂÌÉ«°´Å¥
- var greenBtn = new Button();
- greenBtn.setText("ÂÌÉ«°´Å¥");
- greenBtn.setColor(50, 150, 50);
- greenBtn.setTextColor(255, 255, 255);
- greenBtn.setWidth(100);
- greenBtn.setHeight(40);
- greenBtn.onClick(() => {
- showToast("ÂÌÉ«°´Å¥±»µã»÷");
- });
- buttonContainer.addView(greenBtn);
-
- container.addView(buttonContainer);
- }
- // ½»»¥°´Å¥Ê¾Àý
- function addInteractiveButtonExample(container) {
- var buttonContainer = new Vertical();
- buttonContainer.setSpacing(15);
-
- // ¼ÆÊýÆ÷°´Å¥
- var count = 0;
- var countBtn = new Button();
- countBtn.setText("µã»÷´ÎÊý: " + count);
- countBtn.setWidth(200);
- countBtn.setHeight(45);
- countBtn.setColor(70, 130, 180);
- countBtn.setTextColor(255, 255, 255);
- countBtn.onClick(() => {
- count++;
- countBtn.setText("µã»÷´ÎÊý: " + count);
- showToast("µã»÷´ÎÊý: " + count);
- });
- buttonContainer.addView(countBtn);
-
- // Çл»Îı¾°´Å¥
- var toggleBtn = new Button();
- toggleBtn.setText("ÏÔʾ¸ü¶à");
- toggleBtn.setWidth(150);
- toggleBtn.setHeight(40);
- toggleBtn.onClick(() => {
- var currentText = toggleBtn.getText();
- if (currentText === "ÏÔʾ¸ü¶à") {
- toggleBtn.setText("ÏÔʾ¸üÉÙ");
- } else {
- toggleBtn.setText("ÏÔʾ¸ü¶à");
- }
- showToast("°´Å¥Îı¾ÒÑÇл»");
- });
- buttonContainer.addView(toggleBtn);
-
- container.addView(buttonContainer);
- }
- // ״̬°´Å¥Ê¾Àý
- function addStateButtonExample(container) {
- var buttonContainer = new Horizontal();
- buttonContainer.setSpacing(20);
-
- // ÆôÓÃ/½ûÓð´Å¥
- var enableBtn = new Button();
- enableBtn.setText("½ûÓð´Å¥");
- enableBtn.setWidth(120);
- enableBtn.setHeight(40);
- enableBtn.setColor(150, 150, 150);
- enableBtn.setTextColor(255, 255, 255);
-
- var targetBtn = new Button();
- targetBtn.setText("Ä¿±ê°´Å¥");
- targetBtn.setWidth(120);
- targetBtn.setHeight(40);
- targetBtn.onClick(() => {
- showToast("Ä¿±ê°´Å¥±»µã»÷");
- });
-
- enableBtn.onClick(() => {
- var currentText = enableBtn.getText();
- if (currentText === "½ûÓð´Å¥") {
- enableBtn.setText("ÆôÓð´Å¥");
- targetBtn.setColor(150, 150, 150);
- targetBtn.setTextColor(200, 200, 200);
- // ʵ¼ÊÓ¦ÓÃÖпÉÄÜÐèÒªÉèÖÃÒ»¸ö±êÖ¾À´½ûÓõã»÷
- showToast("°´Å¥ÒѽûÓÃ");
- } else {
- enableBtn.setText("½ûÓð´Å¥");
- targetBtn.setColor(50, 100, 150);
- targetBtn.setTextColor(255, 255, 255);
- showToast("°´Å¥ÒÑÆôÓÃ");
- }
- });
-
- buttonContainer.addView(enableBtn);
- buttonContainer.addView(targetBtn);
-
- container.addView(buttonContainer);
- }
- // ²¼¾Ö°´Å¥Ê¾Àý
- function addLayoutButtonExample(container) {
- var buttonContainer = new Vertical();
- buttonContainer.setSpacing(15);
-
- // ˮƽ²¼¾Ö°´Å¥×é
- var horizontalGroup = new Horizontal();
- horizontalGroup.setSpacing(10);
-
- var hBtn1 = new Button();
- hBtn1.setText("°´Å¥1");
- hBtn1.setWidth(80);
- hBtn1.setHeight(40);
- hBtn1.onClick(() => showToast("°´Å¥1±»µã»÷"));
-
- var hBtn2 = new Button();
- hBtn2.setText("°´Å¥2");
- hBtn2.setWidth(80);
- hBtn2.setHeight(40);
- hBtn2.onClick(() => showToast("°´Å¥2±»µã»÷"));
-
- var hBtn3 = new Button();
- hBtn3.setText("°´Å¥3");
- hBtn3.setWidth(80);
- hBtn3.setHeight(40);
- hBtn3.onClick(() => showToast("°´Å¥3±»µã»÷"));
-
- horizontalGroup.addView(hBtn1);
- horizontalGroup.addView(hBtn2);
- horizontalGroup.addView(hBtn3);
-
- buttonContainer.addView(horizontalGroup);
-
- // ´¹Ö±²¼¾Ö°´Å¥×é
- var verticalGroup = new Vertical();
- verticalGroup.setSpacing(10);
-
- var vBtn1 = new Button();
- vBtn1.setText("´¹Ö±°´Å¥1");
- vBtn1.setWidth(150);
- vBtn1.setHeight(40);
- vBtn1.onClick(() => showToast("´¹Ö±°´Å¥1±»µã»÷"));
-
- var vBtn2 = new Button();
- vBtn2.setText("´¹Ö±°´Å¥2");
- vBtn2.setWidth(150);
- vBtn2.setHeight(40);
- vBtn2.onClick(() => showToast("´¹Ö±°´Å¥2±»µã»÷"));
-
- verticalGroup.addView(vBtn1);
- verticalGroup.addView(vBtn2);
-
- buttonContainer.addView(verticalGroup);
-
- container.addView(buttonContainer);
- }
- // ¸ß¼¶°´Å¥Ê¾Àý
- function addAdvancedButtonExample(container) {
- var buttonContainer = new Vertical();
- buttonContainer.setSpacing(15);
-
- // ´øÍ¼±êЧ¹ûµÄ°´Å¥£¨Ä£Ä⣩
- var iconBtn = new Button();
- iconBtn.setText("🔍 ËÑË÷");
- iconBtn.setWidth(120);
- iconBtn.setHeight(40);
- iconBtn.setColor(70, 130, 180);
- iconBtn.setTextColor(255, 255, 255);
- iconBtn.onClick(() => {
- showToast("ËÑË÷°´Å¥±»µã»÷");
- });
- buttonContainer.addView(iconBtn);
-
- // ³¤Îı¾°´Å¥
- var longTextBtn = new Button();
- longTextBtn.setText("ÕâÊÇÒ»¸öºÜ³¤ºÜ³¤µÄ°´Å¥Îı¾Ê¾Àý");
- longTextBtn.setWidth(200);
- longTextBtn.setHeight(40);
- longTextBtn.onClick(() => {
- showToast("³¤Îı¾°´Å¥±»µã»÷");
- });
- buttonContainer.addView(longTextBtn);
-
- // È·ÈÏ/È¡Ïû°´Å¥×é
- var confirmGroup = new Horizontal();
- confirmGroup.setSpacing(20);
-
- var confirmBtn = new Button();
- confirmBtn.setText("È·ÈÏ");
- confirmBtn.setWidth(100);
- confirmBtn.setHeight(40);
- confirmBtn.setColor(50, 150, 50);
- confirmBtn.setTextColor(255, 255, 255);
- confirmBtn.onClick(() => {
- showToast("È·ÈϲÙ×÷");
- });
-
- var cancelBtn = new Button();
- cancelBtn.setText("È¡Ïû");
- cancelBtn.setWidth(100);
- cancelBtn.setHeight(40);
- cancelBtn.setColor(150, 150, 150);
- cancelBtn.setTextColor(255, 255, 255);
- cancelBtn.onClick(() => {
- showToast("È¡Ïû²Ù×÷");
- });
-
- confirmGroup.addView(confirmBtn);
- confirmGroup.addView(cancelBtn);
-
- buttonContainer.addView(confirmGroup);
-
- container.addView(buttonContainer);
- }
- // ÏÔʾÌáʾÐÅÏ¢
- function showToast(message) {
- printl("Ìáʾ: " + message);
- // ʵ¼ÊÓ¦ÓÃÖпÉÒÔµ÷ÓÃÔÉúµÄtoast¹¦ÄÜ
- }
- // ÈÕÖ¾Êä³öº¯Êý
- function printl(message) {
- console.log("[Button Example] " + message);
- }
- // ´úÂë˵Ã÷£º
- // 1. ±¾Ê¾ÀýչʾÁËButtonµÄ¸÷ÖÖÓ÷¨ºÍÑùʽ
- // 2. °üÀ¨»ù±¾°´Å¥¡¢²ÊÉ«°´Å¥¡¢½»»¥°´Å¥¡¢×´Ì¬°´Å¥¡¢²¼¾Ö°´Å¥ºÍ¸ß¼¶°´Å¥
- // 3. ʵÏÖÁ˰´Å¥µã»÷ʼþ¡¢Îı¾Ð޸ġ¢ÑÕÉ«±ä»¯µÈ½»»¥¹¦ÄÜ
- // 4. ´úÂë×ñÑAIWROKƽ̨µÄ·½·¨¹æ·¶
- // 5. ¿ÉÒÔ¸ù¾Ýʵ¼ÊÐèÇóÐ޸ĺÍÀ©Õ¹¹¦ÄÜ
¸´ÖÆ´úÂë
|
|