1.集成依赖
跟目录下build
allprojects {
repositories {
jcenter()
maven { url 'https://jitpack.io' }
}
}
app build目录下
implementation 'com.github.niorgai:StatusBarCompat:2.1.4'
使用
AppManager.getAppManager().addActivity(this);
StatusBarCompat.setStatusBarColor(this, ContextCompat.getColor(this, R.color.color_5292FE), 0);
AppManager类
private static Stack<Activity> activityStack;
private static AppManager instance;
private AppManager(){}
public static AppManager getAppManager(){
if(instance==null){
instance=new AppManager();
}
return instance;
}
public void addActivity(Activity activity){
if(activityStack==null){
activityStack=new Stack<Activity>();
}
activityStack.add(activity);
}
public Activity currentActivity(){
Activity activity=activityStack.lastElement();
return activity;
}
public void finishActivity(){
Activity activity=activityStack.lastElement();
finishActivity(activity);
}
public void finishActivity(Activity activity){
if(activity!=null){
activityStack.remove(activity);
activity.finish();
activity=null;
}
}
public void finishActivity(Class<?> cls){
for (Activity activity : activityStack) {
if(activity.getClass().equals(cls) ){
finishActivity(activity);
}
}
}
public void finishAllActivity(){
for (int i = 0, size = activityStack.size(); i < size; i++){
if (null != activityStack.get(i)){
activityStack.get(i).finish();
}
}
activityStack.clear();
}
@SuppressWarnings("deprecation")
public void AppExit(Context context) {
try {
finishAllActivity();
ActivityManager activityMgr= (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
activityMgr.restartPackage(context.getPackageName());
System.exit(0);
} catch (Exception e) { }
}