android SwipeBack滑动返回
-
Gitub
地址 -
实战
-
实现步骤:
- 把相应的包给导入
-
在
res
–>values
–>新建attrs.xml
<!-- SwipeBackLayout的xml --> <declare-styleable name="SwipeBackLayout"> <attr name="edge_size" format="dimension" /> <attr name="edge_flag"> <enum name="left" value="0" /> <enum name="right" value="1" /> <enum name="bottom" value="2" /> <enum name="all" value="3" /> </attr> <attr name="shadow_left" format="reference" /> <attr name="shadow_right" format="reference" /> <attr name="shadow_bottom" format="reference" /> </declare-styleable> <attr name="SwipeBackLayoutStyle" format="reference" />
-
导入图片在
xhbpi
:相应的阴影
-
复制或者新建
swipeback_layout.xml
在文件夹layout
<?xml version="1.0" encoding="utf-8"?> <me.imid.swipebacklayout.lib.SwipeBackLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/swipe" android:layout_width="match_parent" android:layout_height="match_parent" />
-
在
styles.xml
的主题里面添加<item name="android:windowIsTranslucent">true</item>
,否则会出现下面问题的情况。 - 最后在每一个
activity
中,将要运用到滑动返回的地方,进行替换,将extends
继承Activity
替换成SwipeBackActivity
即可(默认是从左往右滑是返回)。
或者自行设置,从左,从右,从下滑动:
private SwipeBackLayout mSwipeBackLayout; public void initSwipeBack() { // 初始化 mSwipeBackLayout = getSwipeBackLayout(); // 设置滑动左边关闭的模式 mSwipeBackLayout.setEdgeTrackingEnabled(SwipeBackLayout.EDGE_LEFT); }
其中
SwipeBackLayout.EDGE_LEFT
有几个参数,分别:EDGE_LEFT,EDGE_RIGHT,EDGE_BOTTOM,EDGE_ALL
,即:从左,从右,从下,三个方向。 - 把相应的包给导入
-
android使用swipeBack滑动返回时为什么会出现黑屏现象?
解决:
- 在Manifest中为App设置theme属性(我这叫APPTheme)
- 该theme所有的parent里都要加item
-
<item name="android:windowIsTranslucent">true</item>