-
Gitub
地址 -
實戰
- 實現步驟:
-
把相應的包給導入
Alt text - 在
res
-->values
-->新建attrs.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
<?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`即可(**默認是從左往右滑是返回**)。
或者自行設置,從左,從右,從下滑動:
``` java
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滑動返回時為什么會出現黑屏現象?
**解決**:
1. 在Manifest中為App設置theme屬性(我這叫APPTheme)
2. 該theme所有的parent里都要加item
<item name="android:windowIsTranslucent">true</item>