Skip to content

Commit b6bd89f

Browse files
committed
Add statusbar utils and fix gradle
1 parent 6298f05 commit b6bd89f

File tree

3 files changed

+93
-3
lines changed

3 files changed

+93
-3
lines changed

build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ buildscript {
88
}
99
dependencies {
1010
classpath 'com.android.tools.build:gradle:3.3.2'
11+
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
1112

1213
// NOTE: Do not place your application dependencies here; they belong
1314
// in the individual module build.gradle files
@@ -18,7 +19,7 @@ allprojects {
1819
repositories {
1920
google()
2021
jcenter()
21-
22+
maven { url 'https://jitpack.io' }
2223
}
2324
}
2425

lib/build.gradle

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
apply plugin: 'com.android.library'
2+
apply plugin: 'com.github.dcendents.android-maven'
3+
ext.githubProjectName = 'banana-utils'
24

35
android {
46
compileSdkVersion 28
57

68
defaultConfig {
79
minSdkVersion 14
810
targetSdkVersion 28
9-
versionCode 1
10-
versionName "1.0"
11+
versionCode 2
12+
versionName "0.0.2"
1113

1214
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
1315
}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
package com.zoopark.utils;
2+
3+
import android.app.Activity;
4+
import android.content.Context;
5+
import android.os.Build;
6+
import android.view.Window;
7+
import android.view.WindowManager;
8+
9+
/**
10+
* 状态栏工具类
11+
*/
12+
public class StatusBarUtils {
13+
14+
/**
15+
* 获得 Status Bar 高度
16+
*
17+
* @param context 上下文
18+
* @return int Status Bar 高度
19+
*/
20+
public static int getStatusBarHeight(Context context) {
21+
int height = 0;
22+
int resourceId = context.getResources().getIdentifier("status_bar_height", "dimen", "android");
23+
if (resourceId > 0) {
24+
height = context.getResources().getDimensionPixelSize(resourceId);
25+
}
26+
return height;
27+
}
28+
29+
/**
30+
* Hide Status Bar
31+
*
32+
* @param activity
33+
* @param isVisible
34+
*/
35+
public static void setStatusBarVisibility(Activity activity, boolean isVisible) {
36+
if (isVisible) {
37+
activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
38+
} else {
39+
activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
40+
}
41+
}
42+
43+
/**
44+
* Return whether the status bar is visible.
45+
*
46+
* @param activity
47+
* @return
48+
*/
49+
public static boolean isStatusBarVisible(Activity activity) {
50+
int flags = activity.getWindow().getAttributes().flags;
51+
return (flags & WindowManager.LayoutParams.FLAG_FULLSCREEN) == 0;
52+
}
53+
54+
55+
/**
56+
* 设置状态栏透明
57+
*
58+
* @return ture 设置成功
59+
*/
60+
public static boolean setTranslucent(Activity activity) {
61+
// 在4.4版本以上置StatusBar为透明
62+
if (Build.VERSION.SDK_INT > 18) {
63+
Window window = activity.getWindow();
64+
// 设置 StatusBar 为透明显示
65+
// 需要在 setContentView 之前完成操作
66+
window.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS,
67+
WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
68+
return true;
69+
} else {
70+
return false;
71+
}
72+
}
73+
74+
/**
75+
* 更改状态栏颜色
76+
*
77+
* @param color
78+
*/
79+
public static void setStatusBarColor(Activity activity, int color) {
80+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
81+
Window window = activity.getWindow();
82+
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
83+
window.setStatusBarColor(activity.getResources().getColor(color));
84+
}
85+
}
86+
87+
}

0 commit comments

Comments
 (0)