自动发帖软件

标题: floatUI悬浮窗 实用示例合集 [打印本页]

作者: 发帖软件    时间: 昨天 09:22
标题: floatUI悬浮窗 实用示例合集

如何使用 floatUI 创建不同的 UI 组件,并为它们设置点击事件。每个示例都展示了不同的 UI 布局和事件处理逻辑。

示例 1: 创建一个带有多个按钮的垂直布局,并为每个按钮设置不同的点击事件

var f1 = new floatUI();
f1.loadSXML(`
    <vertical>
        <button text="按钮1" id="button1"/>
        <button text="按钮2" id="button2"/>
        <button text="按钮3" id="button3"/>
    </vertical>
`);

f1.findViewById('button1').setOnClickListener(function() {
    printl("按钮1被点击了");
});

f1.findViewById('button2').setOnClickListener(function() {
    printl("按钮2被点击了");
});

f1.findViewById('button3').setOnClickListener(function() {
    printl("按钮3被点击了");
});


示例 2: 创建一个带有输入框和按钮的布局,点击按钮时获取输入框的内容

var f2 = new floatUI();
f2.loadSXML(`
    <vertical>
        <input id="input1" hint="请输入内容"/>
        <button text="提交" id="submitButton"/>
    </vertical>
`);

f2.findViewById('submitButton').setOnClickListener(function() {
    var inputText = f2.findViewById('input1').getText();
    printl("输入的内容是:" + inputText);
});


示例 3: 创建一个带有复选框的布局,点击按钮时获取复选框的状态

var f3 = new floatUI();
f3.loadSXML(`
    <vertical>
        <checkbox text="选项1" id="checkbox1"/>
        <checkbox text="选项2" id="checkbox2"/>
        <button text="确认" id="confirmButton"/>
    </vertical>
`);

f3.findViewById('confirmButton').setOnClickListener(function() {
    var isChecked1 = f3.findViewById('checkbox1').isChecked();
    var isChecked2 = f3.findViewById('checkbox2').isChecked();
    printl("选项1的状态:" + isChecked1);
    printl("选项2的状态:" + isChecked2);
});


示例 4: 创建一个带有进度条的布局,点击按钮时更新进度条

var f4 = new floatUI();
f4.loadSXML(`
    <vertical>
        <progressbar id="progressBar" max="100"/>
        <button text="更新进度" id="updateButton"/>
    </vertical>
`);

f4.findViewById('updateButton').setOnClickListener(function() {
    var progressBar = f4.findViewById('progressBar');
    var currentProgress = progressBar.getProgress();
    progressBar.setProgress(currentProgress + 10);
    printl("当前进度:" + progressBar.getProgress());
});


示例 5: 创建一个带有单选按钮的布局,点击按钮时获取选中的单选按钮

var f5 = new floatUI();
f5.loadSXML(`
    <vertical>
        <radiogroup id="radioGroup">
            <radiobutton text="选项1" id="radio1"/>
            <radiobutton text="选项2" id="radio2"/>
            <radiobutton text="选项3" id="radio3"/>
        </radiogroup>
        <button text="确认选择" id="confirmButton"/>
    </vertical>
`);

f5.findViewById('confirmButton').setOnClickListener(function() {
    var radioGroup = f5.findViewById('radioGroup');
    var selectedId = radioGroup.getCheckedRadioButtonId();
    var selectedButton = f5.findViewById(selectedId);
    printl("选中的选项是:" + selectedButton.getText());
});


示例 6: 创建一个带有图片的布局,点击按钮时更换图片

var f6 = new floatUI();
f6.loadSXML(`
    <vertical>
        <image id="imageView" src="https://example.com/image1.png"/>
        <button text="更换图片" id="changeImageButton"/>
    </vertical>
`);

f6.findViewById('changeImageButton').setOnClickListener(function() {
    var imageView = f6.findViewById('imageView');
    imageView.setImage("https://example.com/image2.png");
    printl("图片已更换");
});

示例 7: 创建一个带有列表的布局,点击按钮时获取选中的列表项

var f7 = new floatUI();
f7.loadSXML(`
    <vertical>
        <list id="listView">
            <item text="选项1"/>
            <item text="选项2"/>
            <item text="选项3"/>
        </list>
        <button text="获取选中项" id="getSelectedButton"/>
    </vertical>
`);

f7.findViewById('getSelectedButton').setOnClickListener(function() {
    var listView = f7.findViewById('listView');
    var selectedItem = listView.getSelectedItem();
    printl("选中的选项是:" + selectedItem.getText());
});


示例 8: 创建一个带有滑动条的布局,点击按钮时获取滑动条的值

var f8 = new floatUI();
f8.loadSXML(`
    <vertical>
        <seekbar id="seekBar" max="100"/>
        <button text="获取值" id="getValueButton"/>
    </vertical>
`);

f8.findViewById('getValueButton').setOnClickListener(function() {
    var seekBar = f8.findViewById('seekBar');
    var value = seekBar.getProgress();
    printl("当前滑动条的值是:" + value);
});


示例 9: 创建一个带有对话框的布局,点击按钮时显示对话框

var f9 = new floatUI();
f9.loadSXML(`
    <vertical>
        <button text="显示对话框" id="showDialogButton"/>
    </vertical>
`);

f9.findViewById('showDialogButton').setOnClickListener(function() {
    var dialog = new floatUI();
    dialog.loadSXML(`
        <vertical>
            <text text="这是一个对话框"/>
            <button text="关闭" id="closeButton"/>
        </vertical>
    `);

    dialog.findViewById('closeButton').setOnClickListener(function() {
        dialog.dismiss();
    });

    dialog.show();
});


示例 10: 创建一个带有多个布局的复杂 UI,点击按钮时切换布局

var f10 = new floatUI();
f10.loadSXML(`
    <vertical>
        <layout id="layout1">
            <text text="这是布局1"/>
            <button text="切换到布局2" id="switchToLayout2"/>
        </layout>
        <layout id="layout2" visibility="gone">
            <text text="这是布局2"/>
            <button text="切换到布局1" id="switchToLayout1"/>
        </layout>
    </vertical>
`);

f10.findViewById('switchToLayout2').setOnClickListener(function() {
    f10.findViewById('layout1').setVisibility("gone");
    f10.findViewById('layout2').setVisibility("visible");
});

f10.findViewById('switchToLayout1').setOnClickListener(function() {
    f10.findViewById('layout2').setVisibility("gone");
    f10.findViewById('layout1').setVisibility("visible");
});


这些示例展示了如何使用 floatUI 创建不同的 UI 组件,并为它们设置点击事件。你可以根据需要调整这些示例,以适应你的具体需求。

以下是10个复杂且实用的 floatUI 示例,涵盖了不同的功能和场景。每个示例都展示了如何创建和操作浮动界面,并添加不同的交互逻辑。

1. 多按钮联动

var f1 = new floatUI();
f1.loadSXML(`
    <vertical>
        <button text="按钮1" id="button1"/>
        <button text="按钮2" id="button2"/>
        <button text="按钮3" id="button3"/>
    </vertical>
`);

f1.findViewById('button1').setOnClickListener(function() {
    printl("按钮1被点击了");
    f1.findViewById('button2').setText("按钮1被点击了");
});

f1.findViewById('button2').setOnClickListener(function() {
    printl("按钮2被点击了");
    f1.findViewById('button3').setText("按钮2被点击了");
});

f1.findViewById('button3').setOnClickListener(function() {
    printl("按钮3被点击了");
    f1.findViewById('button1').setText("按钮3被点击了");
});

2. 动态添加按钮

var f1 = new floatUI();
f1.loadSXML(`
    <vertical>
        <button text="添加按钮" id="addButton"/>
        <vertical id="buttonContainer"/>
    </vertical>
`);

var buttonCount = 0;
f1.findViewById('addButton').setOnClickListener(function() {
    buttonCount++;
    var newButton = f1.createView('<button text="新按钮' + buttonCount + '"/>');
    newButton.setOnClickListener(function() {
        printl("新按钮" + buttonCount + "被点击了");
    });
    f1.findViewById('buttonContainer').addView(newButton);
});


3. 切换界面

var f1 = new floatUI();
f1.loadSXML(`
    <vertical>
        <button text="切换到界面1" id="switchButton1"/>
        <button text="切换到界面2" id="switchButton2"/>
        <vertical id="container"/>
    </vertical>
`);

var view1 = f1.createView('<vertical><text text="这是界面1"/></vertical>');
var view2 = f1.createView('<vertical><text text="这是界面2"/></vertical>');

f1.findViewById('switchButton1').setOnClickListener(function() {
    f1.findViewById('container').removeAllViews();
    f1.findViewById('container').addView(view1);
});

f1.findViewById('switchButton2').setOnClickListener(function() {
    f1.findViewById('container').removeAllViews();
    f1.findViewById('container').addView(view2);
});


4. 输入框与按钮

var f1 = new floatUI();
f1.loadSXML(`
    <vertical>
        <input id="inputField" hint="请输入内容"/>
        <button text="提交" id="submitButton"/>
        <text id="outputText"/>
    </vertical>
`);

f1.findViewById('submitButton').setOnClickListener(function() {
    var inputText = f1.findViewById('inputField').getText();
    f1.findViewById('outputText').setText("你输入了: " + inputText);
});


5. 进度条与按钮

var f1 = new floatUI();
f1.loadSXML(`
    <vertical>
        <progressbar id="progressBar" max="100"/>
        <button text="开始加载" id="startButton"/>
    </vertical>
`);

f1.findViewById('startButton').setOnClickListener(function() {
    var progress = 0;
    var interval = setInterval(function() {
        progress += 10;
        f1.findViewById('progressBar').setProgress(progress);
        if (progress >= 100) {
            clearInterval(interval);
            printl("加载完成");
        }
    }, 500);
});


6. 列表与点击事件

var f1 = new floatUI();
f1.loadSXML(`
    <vertical>
        <list id="itemList"/>
    </vertical>
`);

var items = ["项目1", "项目2", "项目3", "项目4"];
items.forEach(function(item) {
    var listItem = f1.createView('<text text="' + item + '"/>');
    listItem.setOnClickListener(function() {
        printl("你点击了: " + item);
    });
    f1.findViewById('itemList').addView(listItem);
});


7. 复选框与按钮

var f1 = new floatUI();
f1.loadSXML(`
    <vertical>
        <checkbox text="选项1" id="checkbox1"/>
        <checkbox text="选项2" id="checkbox2"/>
        <button text="提交" id="submitButton"/>
    </vertical>
`);

f1.findViewById('submitButton').setOnClickListener(function() {
    var isChecked1 = f1.findViewById('checkbox1').isChecked();
    var isChecked2 = f1.findViewById('checkbox2').isChecked();
    printl("选项1: " + isChecked1 + ", 选项2: " + isChecked2);
});


8. 图片与点击事件

var f1 = new floatUI();
f1.loadSXML(`
    <vertical>
        <image id="imageView" src="https://via.placeholder.com/150"/>
        <button text="点击图片" id="imageButton"/>
    </vertical>
`);

f1.findViewById('imageButton').setOnClickListener(function() {
    printl("图片被点击了");
});


9. 滑动条与显示值

var f1 = new floatUI();
f1.loadSXML(`
    <vertical>
        <seekbar id="seekBar" max="100"/>
        <text id="seekValue"/>
    </vertical>
`);

f1.findViewById('seekBar').setOnSeekBarChangeListener(function(progress) {
    f1.findViewById('seekValue').setText("当前值: " + progress);
});


10. 多页面切换

var f1 = new floatUI();
f1.loadSXML(`
    <vertical>
        <button text="页面1" id="page1Button"/>
        <button text="页面2" id="page2Button"/>
        <vertical id="pageContainer"/>
    </vertical>
`);

var page1 = f1.createView('<vertical><text text="这是页面1"/></vertical>');
var page2 = f1.createView('<vertical><text text="这是页面2"/></vertical>');

f1.findViewById('page1Button').setOnClickListener(function() {
    f1.findViewById('pageContainer').removeAllViews();
    f1.findViewById('pageContainer').addView(page1);
});

f1.findViewById('page2Button').setOnClickListener(function() {
    f1.findViewById('pageContainer').removeAllViews();
    f1.findViewById('pageContainer').addView(page2);
});


总结

floatUI悬浮窗 实用示例合集 群发软件发帖工具 floatUI悬浮窗 实用示例合集 群发软件发帖工具 floatUI悬浮窗 实用示例合集 群发软件发帖工具 floatUI悬浮窗 实用示例合集 群发软件发帖工具 floatUI悬浮窗 实用示例合集 群发软件发帖工具

这些示例展示了 floatUI 的强大功能,涵盖了从简单的按钮点击到复杂的界面切换和动态内容加载。你可以根据实际需求对这些代码进行修改和扩展,以实现更复杂的功能。






欢迎光临 自动发帖软件 (http://www.fatiegongju.com/) Powered by Discuz! X3.2