View UI——页面右上角添加浮动按钮(设置、退出全屏、进入全屏)

tabindex 用法说明
实现以下功能:(用的是View UI组件库)
在这里插入图片描述
先创建一个存放浮动按钮的<div>

<div class="right_top" v-if="buttonVisible">
</div>
......
//设置对应样式位置大小
.right_top {
  position: fixed; //位置:浮动在其他页面上方
  right: 2vh; //定位按钮距离右边的位置
  top: 0; //上
  width: auto;//宽度
  height: 5vh;
  //width: auto;
 //子元素有margin、border、padding时,会减去子元素content区域相对应的width值
 //父元素的content = 子元素(content + padding + border + margin )
}

新建两个浮动按钮(在创建好的<div>中新建)

此处是用了阿里图标,下载图片后复制到image文件中,以图片形式嵌入按钮中
如果View UI的图标中有想要的字体图标,直接引用即可,比较方便
//引用View UI图标
//方法1
<Button size="small" type="text" shape="circle">
  <Icon type="md-settings" style="font-size: 3vh"/> //可通过style或者class设置字体图标的颜色大小相对位置 
</Button>
//方法2
<Button size="small" type="text" shape="circle"  icon="ios-log-out"></Button>
//引用阿里图标(方法之一,设置好图片样式直接下载,添加到src/assets/image文件夹中,在需要使用的地方直接引用即可)
<Button size="small" type="text" shape="circle">
  <img src="@/assets/image/fullscreen-exit.png" alt="" />
</Button>

设置好按钮后给按钮添加功能

  • 设置——给设置按钮添加下拉框,包含音效开关、单选、退出登录 功能
<Dropdown trigger="click" placement="bottom-start" style="padding-top:0.5vh">
//触发方式,可选值为 hover(悬停)click(点击)contextMenu(右键)custom(自定义),使用 custom 时,需配合 visible 一起使用
//placement:下拉框相对按钮的位置
  <Button size="small" type="text" shape="circle"><Icon type="md-settings" style="font-size: 3vh"/></Button>
  //创建下拉框
  <Dropdown-menu slot="list" style="width:200px">
  	//展示周期
  	<Dropdown-item>
  	</Dropdown-item>
  	//音效开关
  	<Dropdown-item>
  	</Dropdown-item>
  	//退出登录
  	<Dropdown-item>
  	</Dropdown-item>
  </Dropdown-menu>
</Dropdown>

1.展示周期

<span>展示周期:</span>
  <br>
  <RadioGroup id="cycleRadioGroup" v-model="radioNum" vertical @on-change="onCycleChanged()">
    <Radio :label="0">
      <span class="radio_span">24小时</span>
    </Radio>
    <Radio :label="1">
      <span class="radio_span">今天</span>
    </Radio>
    <Radio :label="2">
      <span class="radio_span">7</span>
    </Radio>
    <Radio :label="3">
       <span class="radio_span">30</span>
    </Radio>
  </RadioGroup>
  ......
  data() {
    return {
   radioNum: 2,//单选,默认值“近7天”
   	 }
   },
   
   methods{
    onCycleChanged() {
      this.post("city_brain/switch_cycle", {
        cycleFlag: this.cycleValues[this.radioNum]
      }).then((res) => {
        if (res.errorCode === 0) {
          this.util.setLocalStorage("radioNum", this.radioNum);
          this.showSettings = false;
        }
      });
    }
   },
......
//样式
.radio_span {
  font-size: 14px;
  display: inline-block;
  position: absolute;
  padding-left: 0.5vw;
}
  • 音效开关
<Dropdown-item>
  <span>音效:</span>
  <i-switch size="large" v-model="enableSound" @on-change="onSoundOnOff()">
    <span slot="open">ON</span>
    <span slot="close">OFF</span>
  </i-switch>
</Dropdown-item>
......
enableSound: true, //设置开启未默认状态
......
methods:{
playSound() {
      if (!this.enableSound) {
        return;
      }
      let audio = document.getElementById("music1").play(); //输出music1
      if (audio != undefined) {
        audio.catch(error => {
        //confirm()方法用于显示一个带有指定消息和确认及取消按钮的对话框。如果访问者点击"确定",此方法返回true,否则返回false
          this.$Modal.confirm({  //modal模态弹框
            title: "是否开启音效通知?",
            okText: "开启",
            cancelText: "关闭",
            closable: true,
            content: "<p>开启后新订单通知会播放音效提示</p>",
            //开启
            onOk: () => {
              this.enableSound = true;
              this.playSound();
            },
            //关闭
            onCancel: () => {
              this.enableSound = false;
            }
          });
        });
      }
    },
    //点击事件
     onSoundOnOff() {
      if (this.enableSound) {
        document.getElementById("music1").play();
      }
    },
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
要在悬浮框上角添加一个关闭按,你可以在悬浮框的布局文件中添加一个ImageButton,并设置其位置和点击事件。下面是一种实现方法: 1. 在悬浮框的布局文件(例如`floating_layout.xml`)中,添加一个ImageButton作为关闭按,并设置其位置和样式。 ```xml <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content"> <!-- 其他视图 --> <ImageButton android:id="@+id/close_button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentEnd="true" android:layout_marginEnd="8dp" android:layout_marginTop="8dp" android:src="@drawable/ic_close" /> </RelativeLayout> ``` 2. 在悬浮框的Service中,通过findViewById()方法获取关闭按的引用,并设置点击事件。 ```java public class FloatingService extends Service { private WindowManager windowManager; private View floatingView; @Override public void onCreate() { super.onCreate(); // 获取WindowManager实例 windowManager = (WindowManager) getSystemService(WINDOW_SERVICE); // 加载悬浮框布局文件 floatingView = LayoutInflater.from(this).inflate(R.layout.floating_layout, null); // 获取关闭按的引用 ImageButton closeButton = floatingView.findViewById(R.id.close_button); // 设置关闭按的点击事件 closeButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { stopSelf(); // 关闭Service } }); // 设置悬浮框参数 WindowManager.LayoutParams params = new WindowManager.LayoutParams( WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, PixelFormat.TRANSLUCENT); // 添加悬浮框视图到WindowManager windowManager.addView(floatingView, params); } // ... } ``` 通过以上步骤,你就可以在悬浮框的上角添加一个关闭按,并设置其点击事件为关闭悬浮框的Service。你可以根据需要自定义关闭按的样式和点击逻辑。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

礼礼。

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值