Fetch the repository succeeded.
本项目是基于开源项目EasyFloat进行harmonyos化的移植和开发的,可以通过项目标签以及github地址https://github.com/princekin-f/EasyFloat追踪到原项目版本
移植版本:2.0.2
方式一:
dependencies {
implementation fileTree(dir: 'libs', include: ['.jar', '.har'])
……
}
方式二:
allprojects {
repositories {
mavenCentral()
}
}
implementation 'com.gitee.ts_ohos:EasyFloat:1.0.0'
easyfloat是harmonyos的可拖拽悬浮窗口,支持页面过滤、自定义动画,可设置单页面浮窗、前台浮窗、全局浮窗,浮窗权限按需自动申请, 申请Abliity浮窗需要在根部局传入resId
1.直接在xml布局使用拖拽控件:
<com.lzf.easyfloat.widget.activityfloat.FloatingView
ohos:id="$+id:floatingView"
ohos:height="match_content"
ohos:width="match_content"
ohos:layout_alignment="center"
ohos:left_margin="40vp">
<Image
ohos:height="match_content"
ohos:width="match_content"
ohos:image_src="$media:ic_launcher_round"/>
</com.lzf.easyfloat.widget.activityfloat.FloatingView>
2.完整使用示例:
EasyFloat.with(this)
// 设置浮窗xml布局文件,并可设置详细信息
.setLayout(R.layout.float_app, OnInvokeView { })
// 设置浮窗显示类型,默认只在当前Activity显示,可选一直显示、仅前台显示、仅后台显示
.setShowPattern(ShowPattern.ALL_TIME)
// 设置吸附方式,共15种模式,详情参考SidePattern
.setSidePattern(SidePattern.RESULT_HORIZONTAL)
// 设置浮窗的标签,用于区分多个浮窗
.setTag("testFloat")
// 设置浮窗是否可拖拽,默认可拖拽
.setDragEnable(true)
// 系统浮窗是否包含EditText,仅针对系统浮窗,默认不包含
.hasEditText(false)
// 设置浮窗固定坐标,ps:设置固定坐标,Gravity属性和offset属性将无效
.setLocation(100, 200)
// 设置浮窗的对齐方式和坐标偏移量
.setGravity(Gravity.END or Gravity.CENTER_VERTICAL, 0, 200)
// 设置宽高是否充满父布局,直接在xml设置match_parent属性无效
.setMatchParent(widthMatch = false, heightMatch = false)
// 设置Activity浮窗的出入动画,可自定义,实现相应接口即可(策略模式),无需动画直接设置为null
.setAnimator(DefaultAnimator())
// 设置系统浮窗的出入动画,使用同上
.setAppFloatAnimator(AppFloatDefaultAnimator())
// 设置系统浮窗的不需要显示的页面
.setFilter(MainActivity::class.java, SecondActivity::class.java)
// 设置系统浮窗的有效显示高度(不包含虚拟导航栏的高度),基本用不到,除非有虚拟导航栏适配问题
.setDisplayHeight(OnDisplayHeight { context -> DisplayUtils.rejectedNavHeight(context) })
// 浮窗的一些状态回调,如:创建结果、显示、隐藏、销毁、touchEvent、拖拽过程、拖拽结束。
.registerCallback {
createResult { isCreated, msg, view -> }
show { }
hide { }
dismiss { }
touchEvent { view, motionEvent -> }
drag { view, motionEvent -> }
dragEnd { }
}
// 创建浮窗(这是关键哦)
.show(int resId)
3.Abliity浮窗的相关API:
// 关闭浮窗
dismiss(activity: Activity? = null, floatTag: String? = null)
// 隐藏浮窗
hide(activity: Activity? = null, floatTag: String? = null)
// 显示浮窗
show(activity: Activity? = null, floatTag: String? = null)
// 设置是否可拖拽
setDragEnable(activity: Activity? = null, dragEnable: Boolean, floatTag: String? = null )
// 浮窗是否显示
isShow(activity: Activity? = null, floatTag: String? = null)
// 获取我们设置的浮窗View
getFloatView(activity: Activity? = null, tag: String? = null)
PS:? = null 代表可选参数,不填也行,默认值为null。下同。
4.系统浮窗的相关API:
// 关闭浮窗
dismissAppFloat(tag: String? = null)
// 隐藏浮窗
hideAppFloat(tag: String? = null)
// 显示浮窗
showAppFloat(tag: String? = null)
// 设置是否可拖拽
appFloatDragEnable(dragEnable: Boolean, tag: String? = null)
// 浮窗是否显示
appFloatIsShow(tag: String? = null)
// 获取我们设置的浮窗View
getAppFloatView(tag: String? = null)
// 添加单个浮窗过滤页面
filterActivity(activity: Activity, tag: String? = null)
// 添加多个浮窗过滤页面
filterActivities(tag: String? = null, vararg clazz: Class<>)
// 移除单个浮窗过滤页面
removeFilter(activity: Activity, tag: String? = null)
// 移除多个浮窗过滤页面
removeFilters(tag: String? = null, vararg clazz: Class<>)
// 清空过滤页面
clearFilters(tag: String? = null)
Copyright 2019 Liu Zhenfeng.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。
1. Open source ecosystem
2. Collaboration, People, Software
3. Evaluation model