// 文档地址 https://docs.hamibot.com/

// 文档地址 https://docs.hamibot.com/
const { pay_password } = hamibot.env;

var floatyWin = floaty.window(
<vertical padding="4" h="260dp" layout_weight="1">
<horizontal gravity="center" marginTop="1"> <!-- 减小间距 -->
<text text="计时:" textSize="12" />
<text id="timeDisplay" textSize="12" layout_weight="1" textColor="#FF0000" />
</horizontal>
<horizontal gravity="center_vertical" marginTop="1" visibility="gone"> <!-- 减小间距 -->
<text text="密码:" textSize="12" />
<input id="pwdInput" text="" password="true" layout_weight="1" hint="支付密码" width="100dp" textSize="10" />
</horizontal>
<horizontal gravity="center_vertical" marginTop="1"> <!-- 减小间距 -->
<text text="数量:" textSize="10" />
<button id="countToggleBtn" text="1" h="40"layout_weight="1" textColor="white" textSize="10" marginLeft="5" />
</horizontal>
<horizontal gravity="center" marginTop="1"> <!-- 减小间距 -->
<button id="shopType" text="送到家" h="40"layout_weight="1" style="Widget.AppCompat.Button.Colored" textSize="10" />
</horizontal>
<horizontal gravity="center" marginTop="1"> <!-- 减小间距 -->
<button id="startBtn" text="开始" h="40" layout_weight="1" style="Widget.AppCompat.Button.Colored" textSize="10" />
</horizontal>

<horizontal gravity="center"  marginTop="1"> <!-- 减小间距 -->
  <button id="closeBtn" text="关闭" h="40" layout_weight="1" style="Widget.AppCompat.Button.Colored" textSize="10" />
</horizontal>

</vertical>
);

// 添加居中显示逻辑
floatyWin.setPosition( (device.width / 3)-100, 0); // 自动计算屏幕中心坐标
// 初始化变量
var shopTypeStr = "送到家";
var selectedCount = 1;
var isRunning = true;
var isExpanded = true;

ui.run(function() {
floatyWin.pwdInput.setText(pay_password);
});

// 更新时间的函数 - 只显示时分秒
function updateTime() {
while (isRunning) {
ui.run(function() {
var now = new Date();
var timeStr = util.format("%s:%s:%s:%s",
now.getHours(), now.getMinutes(), now.getSeconds(), now.getMilliseconds());
floatyWin.timeDisplay.setText(timeStr);
});
sleep(88);
}
}

// 数量切换按钮点击事件
floatyWin.shopType.click(function() {
shopTypeStr = shopTypeStr === "送到家" ? "到店取" : "送到家";
floatyWin.shopType.setText(shopTypeStr.toString());
});

// 数量切换按钮点击事件
floatyWin.countToggleBtn.click(function() {
selectedCount = selectedCount === 1 ? 2 : 1;
floatyWin.countToggleBtn.setText(selectedCount.toString());
});
// 启动时间更新线程
threads.start(updateTime);

// 开始按钮点击事件
floatyWin.startBtn.click(function() {
var password = floatyWin.pwdInput.text();
toastLog("开始执行\n数量: " + selectedCount + "\n密码: " + password);
});

// 关闭按钮点击事件
floatyWin.closeBtn.click(function() {
isRunning = false;
floatyWin.close();
exit();
});

// 保持脚本运行
setInterval(function() {}, 500);

将送到家 开始和关闭按钮分别设置不同颜色

已存档
y3rtmwo5zq · 1 个月前
第 1 条补充
·
1 个月前

按钮颜色也要改变,现在只改变了文字颜色

回答

Hamibot AI
1
· 1 个月前

要实现“送到家”、“开始”和“关闭”按钮显示不同颜色,可以通过为每个按钮单独设置 textColor 属性来实现。以下是修改后的代码片段:

// 修改后的按钮定义
<horizontal gravity="center" marginTop="1"> <!-- 减小间距 -->
  <button id="shopType" text="送到家" h="40" layout_weight="1" 
    style="Widget.AppCompat.Button.Colored" textSize="10" 
    textColor="#0000FF" /> <!-- 蓝色 -->
</horizontal>
<horizontal gravity="center" marginTop="1"> <!-- 减小间距 -->
  <button id="startBtn" text="开始" h="40" layout_weight="1" 
    style="Widget.AppCompat.Button.Colored" textSize="10" 
    textColor="#00FF00" /> <!-- 绿色 -->
</horizontal>
<horizontal gravity="center" marginTop="1"> <!-- 减小间距 -->
  <button id="closeBtn" text="关闭" h="40" layout_weight="1" 
    style="Widget.AppCompat.Button.Colored" textSize="10" 
    textColor="#FF0000" /> <!-- 红色 -->
</horizontal>

说明:

  1. textColor 属性:通过设置 textColor="#颜色代码" 可修改按钮文字颜色。

    • #0000FF 是蓝色,#00FF00 是绿色,#FF0000 是红色。
    • 你可以替换为其他颜色代码(如 #FFA500 橙色)。
  2. 保持原有样式style="Widget.AppCompat.Button.Colored" 保留了按钮的默认彩色样式,仅通过 textColor 覆盖文字颜色。

  3. 效果

    • "送到家" 按钮显示蓝色文字
    • "开始" 按钮显示绿色文字
    • "关闭" 按钮显示红色文字

如果需要进一步调整按钮背景色或其他样式,可能需要使用自定义布局或 canvas 绘制,但上述方法已满足基础颜色区分需求。


补充回答 1

要实现按钮颜色(背景色)的差异化,需为每个按钮添加 backgroundColor 属性。以下是修改后的代码片段:

// 修改后的按钮定义
<horizontal gravity="center" marginTop="1"> <!-- 减小间距 -->
  <button id="shopType" text="送到家" h="40" layout_weight="1" 
    style="Widget.AppCompat.Button.Colored" textSize="10" 
    textColor="#FFFFFF" backgroundColor="#0000FF" /> <!-- 蓝色背景 + 白色文字 -->
</horizontal>
<horizontal gravity="center" marginTop="1"> <!-- 减小间距 -->
  <button id="startBtn" text="开始" h="40" layout_weight="1" 
    style="Widget.AppCompat.Button.Colored" textSize="10" 
    textColor="#FFFFFF" backgroundColor="#00FF00" /> <!-- 绿色背景 + 白色文字 -->
</horizontal>
<horizontal gravity="center" marginTop="1"> <!-- 减小间距 -->
  <button id="closeBtn" text="关闭" h="40" layout_weight="1" 
    style="Widget.AppCompat.Button.Colored" textSize="10" 
    textColor="#FFFFFF" backgroundColor="#FF0000" /> <!-- 红色背景 + 白色文字 -->
</horizontal>

关键修改说明:

  1. backgroundColor 属性

    • 通过 backgroundColor="#颜色代码" 设置按钮背景色。
    • 示例:#0000FF(蓝色)、#00FF00(绿色)、#FF0000(红色)。
  2. 文字颜色适配

    • 由于按钮背景色可能影响文字可读性,建议搭配 textColor="#FFFFFF"(白色)确保清晰可见。
  3. 保留原有样式

    • style="Widget.AppCompat.Button.Colored" 保持按钮的默认彩色样式,backgroundColor 会覆盖其默认背景色。

效果:

  • "送到家" 按钮:蓝色背景 + 白色文字
  • "开始" 按钮:绿色背景 + 白色文字
  • "关闭" 按钮:红色背景 + 白色文字

如果 backgroundColor 未生效,可能需要通过自定义样式或 Android 资源文件进一步调整。

ℹ️ 本回答由 AI 生成,内容仅供参考