oubowu / slideback Goto Github PK
View Code? Open in Web Editor NEWA library to close an activity with swipe gestures.
A library to close an activity with swipe gestures.
导入到我自己的项目中,谢谢.
当页面内有视频播放时,侧滑会出现一抖一抖的异常。这种情况怎么处理?
SlideBackHelper的attach方法的preActivity偶尔为null
final Activity[] preActivity = {helper.getPreActivity()};
final View[] preContentView = {getContentView(preActivity[0])};
导致该方法报错crash
public static ViewGroup getDecorView(Activity activity) {
return (ViewGroup) activity.getWindow().getDecorView();
}
推测app在后台是很久没打开,上级页面被回收。这应该怎么处理??望解答
在SecondActivity界面的,跳转侧滑页面按钮左下边缘,滑动一下放开,再长按滑动(不行可多操作几次),界面会突然闪回去
在有ViewPager的页面,ViewPager处于第一页,经常要滑动两三次,才可以触发侧滑返回。
public class StatusBarUtil {
public static final int DEFAULT_STATUS_BAR_ALPHA = 112;
@TargetApi(Build.VERSION_CODES.KITKAT)
public static boolean setTranslucentStatus(Activity activity, boolean on) {
Window win = activity.getWindow();
WindowManager.LayoutParams winParams = win.getAttributes();
final int bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;
if (on) {
winParams.flags |= bits;
} else {
winParams.flags &= ~bits;
}
win.setAttributes(winParams);
return on;
}
/**
* 为滑动返回界面设置状态栏颜色
*
*/
public static void setColorForSwipeBack(Activity activity, @ColorInt int color) {
setColorForSwipeBack(activity, color, 0);
}
/**
* 为滑动返回界面设置状态栏颜色
*
* @param activity 需要设置的activity
* @param color 状态栏颜色值
* @param statusBarAlpha 状态栏透明度
*/
public static void setColorForSwipeBack(Activity activity, @ColorInt int color, int statusBarAlpha) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
ViewGroup contentView = ((ViewGroup) activity.findViewById(android.R.id.content));
if (contentView == null) return;
View rootView = contentView.getChildAt(0);
int statusBarHeight = getStatusBarHeight(activity);
if (rootView != null && rootView instanceof CoordinatorLayout) {
final CoordinatorLayout coordinatorLayout = (CoordinatorLayout) rootView;
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
coordinatorLayout.setFitsSystemWindows(false);
contentView.setBackgroundColor(calculateStatusColor(color, statusBarAlpha));
boolean isNeedRequestLayout = contentView.getPaddingTop() < statusBarHeight;
if (isNeedRequestLayout) {
contentView.setPadding(0, statusBarHeight, 0, 0);
coordinatorLayout.post(new Runnable() {
@Override
public void run() {
coordinatorLayout.requestLayout();
}
});
}
} else {
coordinatorLayout.setStatusBarBackgroundColor(calculateStatusColor(color, statusBarAlpha));
}
} else {
contentView.setPadding(0, statusBarHeight, 0, 0);
contentView.setBackgroundColor(calculateStatusColor(color, statusBarAlpha));
}
setTranslucentStatus(activity, true);
}
}
/**
* 获取状态栏高度
*
* @param context context
* @return 状态栏高度
*/
private static int getStatusBarHeight(Context context) {
// 获得状态栏高度
int resourceId = context.getResources().getIdentifier("status_bar_height", "dimen", "android");
return context.getResources().getDimensionPixelSize(resourceId);
}
/**
* 计算状态栏颜色
*
* @param color color值
* @param alpha alpha值
* @return 最终的状态栏颜色
*/
private static int calculateStatusColor(@ColorInt int color, int alpha) {
float a = 1 - alpha / 255f;
int red = color >> 16 & 0xff;
int green = color >> 8 & 0xff;
int blue = color & 0xff;
red = (int) (red * a + 0.5);
green = (int) (green * a + 0.5);
blue = (int) (blue * a + 0.5);
return 0xff << 24 | red << 16 | green << 8 | blue;
}
}
public class StatusBarView extends View {
public StatusBarView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public StatusBarView(Context context) {
super(context);
}
}
上面的方法改自StatusBarUtil,修改了setTranslucentStatus(activity, true);
根布局如果是CoordinatorLayout,加上android:fitsSystemWindows="true"
;如果不是,就不要加android:fitsSystemWindows="true"
,并且需要在根布局设置背景background,不然背景色和状态栏一样(style设置的背景失效,上面的方法相当重新覆盖了背景色)。如果布局有EditText,请用CoordinatorLayout,不然顶不上去
代码如下::
//滑动关闭activity
public void slideBack(){
mSlideBackLayout = SlideBackHelper.attach(
this,
OkbuyApplication.getActivityHelper(),
new SlideConfig.Builder()
.rotateScreen(true)
.edgeOnly(false)
.lock(false)
.edgePercent(0.1f)
.slideOutPercent(0.5f).create(),
// 滑动的监听
new OnSlideListener() {
@OverRide
public void onSlide(@FloatRange(from = 0.0, to = 1.0) float percent) {
if(percent > 0.0){
cancelCountDown();
}
}
@OverRide
public void onOpen() {
setCountDownForSlideBack();
}
@OverRide
public void onClose() {
setResult(Activity.RESULT_OK);
}
});
}
断点调试没发现问题,莫名其妙,望大神指点一二
demo没有这个问题,我在项目里用的时候出现,一直滑就不会出现,这个问题要怎么查?
列表页快速上滑的时候,很容易关闭页面,几率很高的。这个怎么整?有没有合适的解决办法,已经集成进去了,刚发现这个问题,要废了,求助大神~
SlideBackHelper 中getDecorView方法空指针异常,是不是activity被回收了?
初步判断是特定的Fragment引起的某个冲突, 当侧滑返回时, 页面会闪回之前的页面
给webview加侧滑导致webview顶部被遮住一部分,部分机型出现,应该是measure出问题了
进入一个界面,然后滑动返回,上一个界面过度绘制会变红,请问能解决这个问题么?
mCacheView.draw(canvas);
报错在这一行,貌似是发生了递归调用
锁死后返回键onBackPressed无法触发,屏幕无法点击,半透明阴影遮罩,但是抽屉没有打开,只能关掉应用重开,有遇到这个问题吗?
如题。今天找了滑动返回的库找了很久,大部分都是基于swipeBackLayout做的,必须要设置透明主题,但是透明主题会引起各种bug,终于找到作者这个不用设置透明主题的了。大概看了下源码,觉得思路还是比较好的,希望能上传jcenter
RT
如题
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.