{"id":13645361,"url":"https://github.com/liuguangli/FloatUtil","last_synced_at":"2025-04-21T14:30:47.341Z","repository":{"id":96127677,"uuid":"71748074","full_name":"liuguangli/FloatUtil","owner":"liuguangli","description":"An easy util for floatWindow ","archived":false,"fork":false,"pushed_at":"2017-03-06T07:15:59.000Z","size":3211,"stargazers_count":329,"open_issues_count":6,"forks_count":58,"subscribers_count":10,"default_branch":"master","last_synced_at":"2024-08-02T01:25:20.090Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/liuguangli.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2016-10-24T03:21:00.000Z","updated_at":"2024-06-19T09:35:18.000Z","dependencies_parsed_at":"2023-04-01T04:19:38.331Z","dependency_job_id":null,"html_url":"https://github.com/liuguangli/FloatUtil","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/liuguangli%2FFloatUtil","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/liuguangli%2FFloatUtil/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/liuguangli%2FFloatUtil/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/liuguangli%2FFloatUtil/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/liuguangli","download_url":"https://codeload.github.com/liuguangli/FloatUtil/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223868083,"owners_count":17217026,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-02T01:02:34.007Z","updated_at":"2025-04-21T14:30:47.326Z","avatar_url":"https://github.com/liuguangli.png","language":"Java","funding_links":[],"categories":["悬浮窗"],"sub_categories":[],"readme":"## FloatUtil\n[![](https://jitpack.io/v/liuguangli/FloatUtil.svg)](https://jitpack.io/#liuguangli/FloatUtil)\n\n一个简单的浮窗工具。封装了浮窗的使用方法，并做了系统、版本的兼容处理，帮你绕过权限的限制。\n\n![浮窗](https://github.com/liuguangli/FloatUtil/blob/master/files/float_drag.gif)\n## 开始\n项目使用 [jitpack](https://jitpack.io) 做开源库的托管，你需要在 .gradle 中添加  [jitpack](https://jitpack.io) \n的仓库。\n\n    allprojects {\n        repositories {\n            jcenter()\n            maven { url \"https://jitpack.io\" }\n        }\n    }\n    \n在添加 FloatUtil 的依赖引用：\n   \n   \n    dependencies {\n         compile 'com.github.liuguangli:FloatUtil:-SNAPSHOT'\n    }\n\n\n### 创建一个简单的浮窗\n\n      SimpleView floatView = new SimpleView(this);\n      FloatUtil.showFloatView(floatView, null);\n    \nSimpleView 是你自定义的 View，就这么简单，浮窗显示出来了。\n\n![浮窗](https://github.com/liuguangli/FloatUtil/blob/master/files/simple_float.gif)\n    \n### 关闭浮窗\n\n      FloatUtil.hideFloatView(context, SimpleView.class, false);\n同一个 View 类，同时只能显示一个实例， 关闭的时候指定一个 class 对象便能知道关闭哪个浮窗实例。 最后一个参数\n决定要不要将当前实例缓存，以便下次快速显示并维持状态，false 代表不缓存，true 表示要缓存。\n\n### 向浮窗传递参数\n\nFloatUtil 提供了一个接口：ParamReceiver。你自定义的 View 实现这个接口便能接收参数。\n\n     public class SimpleViewWitchParam extends FrameLayout implements ParamReceiver {\n        public static final java.lang.String PARAM = \"PARAM\";\n        public static final String CONTENT = \"content\";\n        @Override\n        public void onParamReceive(Bundle bundle) {\n            // 在这个回调方法中接收参数并解析\n            if (bundle != null) {\n                String param = bundle.getString(PARAM);\n                \n            }\n        }\n    }\n    \n然后在添加这个 SimpleViewWitchParam 到浮窗。\n     \n        SimpleViewWitchParam floatView = new SimpleViewWitchParam(this);\n        Bundle bundle = new Bundle();\n        bundle.putString(SimpleViewWitchParam.PARAM, \"我是传过来的参数\");\n        FloatUtil.showFloatView(floatView, bundle);\n        \n![浮窗](https://github.com/liuguangli/FloatUtil/blob/master/files/float_param.gif)        \n        \n### 指定层级和对齐方式\n       \n        SimpleViewWitchParam floatView = new SimpleViewWitchParam(this);\n        // 居中对齐，浮窗层级为 WindowManager.LayoutParams.TYPE_TOAST\n        FloatUtil.showFloatView(floatView, Gravity.CENTER,WindowManager.LayoutParams.TYPE_TOAST , null);\n        \n![浮窗](https://github.com/liuguangli/FloatUtil/blob/master/files/float_center.gif)        \n        \n浮窗类型 type 决定了浮窗的层级，关于浮窗层级的详细理解可以参考我的博客:[《浮窗开发之窗口层级》](http://www.liuguangli.win/archives/476),\nAndroid 系统对窗体的某些层级有权限限制，例如 WindowManager.LayoutParams.TYPE_PHONE 类型的窗体需要授权。\n\n### 智能浮窗（突破授权）\n\nFloatUtil 提供智能方式添加浮窗，针对特定的系统版本、机型为你选择合适的浮窗 type ，越过授权（详细参考我的博客：[越过用户授权使用浮窗](http://www.liuguangli.win/archives/484))，你不需要再去关注复杂的处理过程。\n   \n        SimpleViewWitchParam floatView = new SimpleViewWitchParam(this);\n        Bundle bundle = new Bundle();\n        bundle.putString(SimpleViewWitchParam.PARAM, \"智能浮窗\");\n        // 指定浮窗显示的位置\n        Point point = new Point();\n        point.x = 0;\n        point.y = 0;\n        FloatUtil.showSmartFloat(floatView, Gravity.CENTER, point, bundle);\n                \n\n## MIT License\n\nCopyright (c) 2016 刘光利\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fliuguangli%2FFloatUtil","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fliuguangli%2FFloatUtil","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fliuguangli%2FFloatUtil/lists"}