在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:Android_Slide_To_Close开源软件地址:https://gitee.com/ouyangfeng/Android_Slide_To_Close开源软件介绍:Snake温馨提示:Snake已经完成AndroidX适配,请放心使用! 旧版本文档最新版本
特性介绍
Demo下载体验扫描上方二维码 或 直接点这里下载 使用方法1)添加依赖 dependencies { // x.x.x代表上方表格中对应模块最新版本 implementation 'com.youngfeng.android:snake-androidx:x.x.x' annotationProcessor 'com.youngfeng.android:snake-compiler-androidx:x.x.x'} 注:如果使用Kotlin,请将annotationProcessor修改为kapt 2)在Application中对初始化Snake public class SnakeApplication extends Application { @Override public void onCreate() { super.onCreate(); // 对Snake进行初始化 Snake.init(this); }} Activity集成步骤在需要开启滑动返回的Activity类上方添加注解 @EnableDragToClose()public class FirstActivity extends Activity Fragment集成步骤在Fragment中使用Snake实现滑动关闭比Activity更加灵活,推荐大家使用Fragment进行页面布局。目前,Snake提供了两种方式在Fragment中开启滑动关闭。 方法一:动态配置第一步:在需要开启滑动返回的Fragment类上方添加注解 @EnableDragToClose(public class FirstFragment extends Fragment { 第二步:使用Snake提供的方法动态创建Fragment实例。 // 如果Fragment继承自androidx.fragment.app.Fragment, 则使用方法newProxySupport创建实例FirstFragment fragment = Snake.newProxySupport(FirstFragment.class);// 如果Fragment继承自android.app.Fragment, 则使用个方法newProxy创建实例FirstFragment fragment = Snake.newProxy(FirstFragment.class); 注意:在不存在默认构造函数的情况下,你需要使用注解 @EnableDragToClose()public class FirstFragment extends Fragment { @PrimaryConstructor public FirstFragment(int x, int y) { } ...} 在使用了注解标记构造函数的情况下,使用Snake方法创建实例的时候需要传入构造参数,如下所示: FirstFragment fragment = Snake.newProxySupport(FirstFragment.class, 1, 2); 方法二:使用继承方式集成按照下面的对应关系,改变你的Fragment父类即可完成滑动关闭集成:
注意1)从0.4.0版本开始,support库将不再提供支持,如需继续使用support库版本Fragment,请使用0.4.0以下版本,Activity不受影响。 2)由于Android 9.0已经舍弃了 3)Snake与Navigation暂时不兼容,如需使用Snake实现滑动关闭,需要自己控制Fragment页面导航。 滑动参数配置通常情况下,完成上面的步骤,你已经可以正常使用滑动关闭功能了。可是,有些同学可能希望对滑动样式进行定制化。别担心,Snake提供了两种方式对滑动参数进行配置。
<?xml version="1.0" encoding="utf-8"?><snake> <config> <!-- 设置为true,根Activity也能够滑动关闭,这很奇怪!不建议修改这个变量的默认值 --> <enable_for_root_activity>false</enable_for_root_activity> <!-- 设置为true,将监听当前页面所有位置往右快速滑动手势 --> <only_listen_to_fast_swipe>false</only_listen_to_fast_swipe> <!-- 快速滑动最低检测速度,不建议修改。过高会影响灵敏度,过低会导致误判 --> <min_velocity>2000</min_velocity> <!-- 设置为true,滑动时左侧边缘阴影将被隐藏, 这个变量的默认值也不建议修改 --> <hide_shadow_of_edge>false</hide_shadow_of_edge> <!-- 阴影边缘渐变色起始颜色 --> <shadow_start_color>#00000000</shadow_start_color> <!-- 阴影边缘渐变色结束颜色 --> <shadow_end_color>#50000000</shadow_end_color> <!-- 类似iPhone X, 从底部边缘快速上滑回到桌面 (实验性功能,默认关闭) --> <enable_swipe_up_to_home>false</enable_swipe_up_to_home> <!-- 是否允许页面联动,默认为true --> <allow_page_linkage>true</allow_page_linkage> </config></snake> 修改模板参数,复制当前xml文件,放到主工程目录的assets下面即可,名称必须依然是snake.xml,不能修改!
@EnableDragToClose()@SetDragParameter(minVelocity = 2000, hideShadowOfEdge = false ...)public class FirstActivity extends Activity 其它接口介绍
版本兼容问题处理support替换为androidx实现 由于 移除SnakeAnimationController接口 从 android.app.Fragment替换为androidx实现 从 依赖声明方式发生变化,需要增加 implementation 'com.youngfeng.android:snake-androidx:x.x.x'annotationProcessor 'com.youngfeng.android:snake-compiler-androidx:x.x.x' 最佳实践1)为了避免出现大量重复代码,推荐大家使用继承的方式使用Snake。 2)Activity的启动是一个非常耗时的过程,为了体验效果更佳,推荐使用全Fragment设计,或者单Activity+多Fragment设计。 3)遇到问题请先查看Wiki,如果没有你想要的答案,请添加QQ交流群288177681及时反馈。 4)为了在Activity中获得最佳使用体验,建议大家在style文件中添加如下配置: <item name="android:windowIsTranslucent">true</item> 5) 混淆配置# 如果已经应用该规则,无需重复配置-keepattributes *Annotation*-keep class **.*_SnakeProxy-keep @com.youngfeng.snake.annotations.EnableDragToClose public class * 微信公众号微信公众号也是一个高效的问题反馈平台,如需帮助请在微信公众号中给我留言,我会第一时间查看!* QQ交流群QQ群:288177681 如果你在使用过程中遇到了任何问题,欢迎加群交流。如果你想给作者支持,请点击上方star支持。 PS: 如果你在产品中使用了 LicenseCopyright 2018 Ouyangfeng Office 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, softwaredistributed 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 andlimitations under the License. |
请发表评论