使您的活动可以滑动关闭
中文 | English 仅需三行代码即可关闭活动滑动。 部分代码修改自 SwipeBackLayout
compile 'com.jude:swipebackhelper:3.1.2'将以下内容添加到style.xml:
//if you don't set this the background will be black when you slide.
<item name="android:windowIsTranslucent">true</item>
//set the right in/out animation of Activity,you can change this to yours
<item name="android:windowAnimationStyle">@style/SlideRightAnimation</item>注意 为主活动设置一个独立的主题,该主题应位于底部且不能滑动。并通过 setSwipeBackEnable(false) 设置活动不允许滑动
<style name="MainTheme" parent="AppTheme">
<item name="android:windowIsTranslucent">false</item>
</style>将此代码添加到您的 Activity 的生命周期中。
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
SwipeBackHelper.onCreate(this);
}
@Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
SwipeBackHelper.onPostCreate(this);
}
@Override
protected void onDestroy() {
super.onDestroy();
SwipeBackHelper.onDestroy(this);
}如果需要更多设置,可以在 SwipeBackHelper.onCreate() 之后使用:
…Copyright 2015 Jude
本文件受 Apache 许可证第 2.0 版 (以下简称"许可证") 限制;您不得在不遵守许可证的情况下使用本文件。您可以在以下网址获取许可证的副本:
暂无开放 Issues,或尚未同步最近议题。