Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

「update」update demo and readme #3

Merged
merged 1 commit into from
Dec 28, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
119 changes: 116 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
:running:BGASwipeBackLayout-Android:running:
============

通过修改 support-v4 包中 SlidingPaneLayout 的源码来实现滑动返回布局
## 功能介绍

- [x] 通过修改 support-v4 包中 SlidingPaneLayout 的源码来实现滑动返回布局
- [x] 动态设置滑动返回是否可用
- [x] 动态设置是否仅仅跟踪左侧边缘的滑动返回
- [x] 动态设置是否显示滑动返回的阴影效果

## 效果图与示例 apk

Expand All @@ -11,8 +16,116 @@

![BGABannerDemo apk文件二维](https://cloud.githubusercontent.com/assets/8949716/21510942/c8e9c9e0-ccd4-11e6-9757-bbc6653cccdb.png)


## 文档待完善,着急的猿友就先看 [demo](https://github.com/bingoogolapple/BGASwipeBackLayout-Android/tree/master/demo) 吧
### 1.添加 Gradle 依赖
[ ![Download](https://api.bintray.com/packages/bintray/jcenter/cn.bingoogolapple%3Abga-swipebacklayout/images/download.svg) ](https://bintray.com/bintray/jcenter/cn.bingoogolapple%3Abga-swipebacklayout/_latestVersion) bga-swipebacklayout 后面的「latestVersion」指的是左边这个 Download 徽章后面的「数字」,请自行替换。

```groovy
dependencies {
compile 'cn.bingoogolapple:bga-swipebacklayout:latestVersion@aar'

// 换成己工程里依赖的 support-v4 的版本
compile 'com.android.support:support-v4:25.1.0'
}
```

### 2.为需要支持滑动返回的 Activity 设置透明主题 AppTheme.Transparent

```java
<!-- 这里面的内容改成你自己项目里的 -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!--colorPrimaryDark对应状态栏的颜色-->
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<!--colorPrimary对应ActionBar的颜色-->
<item name="colorPrimary">@color/colorPrimary</item>
<!-- 底部导航栏的颜色 -->
<item name="android:navigationBarColor" tools:targetApi="lollipop">@color/navigationBarColor</item>
<item name="android:windowBackground">@color/windowBackground</item>
<!--colorAccent 对应EditText编辑时、RadioButton选中、CheckBox等选中时的颜色-->
<item name="colorAccent">@color/colorAccent</item>
</style>

<!-- 用于开启滑动返回功能的 Activity -->
<style name="AppTheme.Transparent">
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowIsTranslucent">true</item>
</style>
```

### 3.将下面的代码拷贝到你自己的 BaseActivity 中,建议参考 demo 里的这个 [BaseActivity](https://github.com/bingoogolapple/BGASwipeBackLayout-Android/blob/master/demo/src/main/java/cn/bingoogolapple/swipebacklayout/demo/activity/BaseActivity.java) 来设置界面跳转动画

```java
public class BaseActivity extends AppCompatActivity implements BGASwipeBackLayout.PanelSlideListener {
protected BGASwipeBackLayout mSwipeBackLayout;

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
initSwipeBackFinish();
super.onCreate(savedInstanceState);
}

/**
* 初始化滑动返回
*/
private void initSwipeBackFinish() {
if (isSupportSwipeBack()) {
mSwipeBackLayout = new BGASwipeBackLayout(this);
// 将该滑动返回控件添加到 Activity 上
mSwipeBackLayout.attachToActivity(this);
// 设置滑动监听器
mSwipeBackLayout.setPanelSlideListener(this);

// 下面三项可以不配置,这里只是为了讲述接口用法

// 设置滑动返回是否可用。默认值为 true
mSwipeBackLayout.setSwipeBackEnable(true);
// 设置是否仅仅跟踪左侧边缘的滑动返回。默认值为 true
mSwipeBackLayout.setIsOnlyTrackingLeftEdge(true);
// 设置是否显示滑动返回的阴影效果。默认值为 true
mSwipeBackLayout.setIsNeedShowShadow(true);
}
}

/**
* 是否支持滑动返回。默认支持,如果某个界面不想支持滑动返回则重写该方法返回 false 即可
*
* @return
*/
protected boolean isSupportSwipeBack() {
return true;
}

/**
* 动态设置滑动返回是否可用。
*
* @param swipeBackEnable
*/
protected void setSwipeBackEnable(boolean swipeBackEnable) {
if (mSwipeBackLayout != null) {
mSwipeBackLayout.setSwipeBackEnable(swipeBackEnable);
}
}


@Override
public void onPanelClosed(View view) {
}

@Override
public void onPanelOpened(View view) {
swipeBackward();
}

@Override
public void onPanelSlide(View view, float v) {
}
}
```

## demo 中用到的第三方库

* [StatusBarUtil](https://github.com/laobie/StatusBarUtil) A util for setting status bar style on Android App
* [BGAAdapter-Android](https://github.com/bingoogolapple/BGAAdapter-Android) 在 AdapterView 和 RecyclerView 中通用的 Adapter 和 ViewHolder。RecyclerView 支持 DataBinding 、多种 Item 类型、添加 Header 和 Footer
* 谷爹的 support 包

## 代码是最好的老师,更多详细用法请查看 [demo](https://github.com/bingoogolapple/BGASwipeBackLayout-Android/tree/master/demo):feet:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,13 @@ private void initSwipeBackFinish() {
mSwipeBackLayout.attachToActivity(this);
mSwipeBackLayout.setPanelSlideListener(this);

// 下面三项可以不配置,这里只是为了讲述接口用法

// 设置滑动返回是否可用。默认值为 true
mSwipeBackLayout.setSwipeBackEnable(true);
// 设置是否仅仅跟踪左侧边缘的滑动返回。默认值为 true
mSwipeBackLayout.setIsOnlyTrackingLeftEdge(true);
// 设置是否显示滑动返回的阴影效果。默认值为 true
mSwipeBackLayout.setIsNeedShowShadow(true);
}
}
Expand Down
13 changes: 7 additions & 6 deletions demo/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<resources xmlns:tools="http://schemas.android.com/tools">

<!-- 这里面的内容根据你自己项目做修改 -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!--colorPrimaryDark对应状态栏的颜色-->
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
Expand All @@ -14,12 +15,7 @@
<item name="colorAccent">@color/colorAccent</item>
</style>

<style name="AppTheme.Fullscreen">
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">@null</item>
</style>

<!-- 适用于开启滑动返回功能的Activity -->
<!-- 适用于开启滑动返回功能的 Activity -->
<style name="AppTheme.Transparent">
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowIsTranslucent">true</item>
Expand All @@ -30,6 +26,11 @@
<item name="android:windowDisablePreview">true</item>
</style>

<style name="AppTheme.Fullscreen">
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">@null</item>
</style>

<style name="AppTheme.Transparent.Fullscreen">
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">@null</item>
Expand Down