├── .gitignore
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── github
│ │ └── xubo
│ │ └── statusbarutils
│ │ └── sample
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── github
│ │ │ └── xubo
│ │ │ └── statusbarutils
│ │ │ └── sample
│ │ │ ├── MainActivity.java
│ │ │ ├── MyScrollView.java
│ │ │ ├── Page1Activity.java
│ │ │ ├── Page2Activity.java
│ │ │ ├── Page3Activity.java
│ │ │ ├── Page4Activity.java
│ │ │ ├── Tab1Fragment.java
│ │ │ ├── Tab2Fragment.java
│ │ │ └── TabActivity.java
│ └── res
│ │ ├── color
│ │ └── main_radio_color.xml
│ │ ├── drawable-v24
│ │ └── ic_launcher_foreground.xml
│ │ ├── drawable-xhdpi
│ │ └── img2.jpg
│ │ ├── drawable-xxhdpi
│ │ └── img1.jpg
│ │ ├── drawable
│ │ └── ic_launcher_background.xml
│ │ ├── layout
│ │ ├── activity_main.xml
│ │ ├── activity_page1.xml
│ │ ├── activity_page2.xml
│ │ ├── activity_page3.xml
│ │ ├── activity_page4.xml
│ │ ├── activity_tab.xml
│ │ ├── fragment_tab1.xml
│ │ └── fragment_tab2.xml
│ │ ├── mipmap-anydpi-v26
│ │ ├── ic_launcher.xml
│ │ └── ic_launcher_round.xml
│ │ ├── mipmap-hdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-mdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ └── values
│ │ ├── colors.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── com
│ └── github
│ └── xubo
│ └── statusbarutils
│ └── sample
│ └── ExampleUnitTest.java
├── build.gradle
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── screen
└── screen.gif
├── settings.gradle
└── statusbarutils
├── .gitignore
├── build.gradle
├── proguard-rules.pro
├── src
├── androidTest
│ └── java
│ │ └── com
│ │ └── github
│ │ └── xubo
│ │ └── statusbarutils
│ │ └── ExampleInstrumentedTest.java
├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── github
│ │ │ └── xubo
│ │ │ └── statusbarutils
│ │ │ ├── FlymeStatusbarColorUtils.java
│ │ │ ├── OSInfo.java
│ │ │ └── StatusBarUtils.java
│ └── res
│ │ └── values
│ │ └── strings.xml
└── test
│ └── java
│ └── com
│ └── github
│ └── xubo
│ └── statusbarutils
│ └── ExampleUnitTest.java
└── version.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea
5 | .DS_Store
6 | /build
7 | /captures
8 | .externalNativeBuild
9 | gradle.properties
10 | bintray.properties
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ## 1、描述
2 | **`StatusBarUtils`是Android状态栏工具类,支持设置状态栏颜色、设置状态栏沉浸式、状态栏字符颜色深色切换;并对`小米`、`魅族`、`OPPO`等机型进行适配。**
3 |
4 | ## 2、方法
5 | |方法名|描述|机型支持
6 | |:---:|:---:|:---:|
7 | | setStatusBarColor | 设置状态栏颜色|支持4.4以上的所有机型
8 | | setStatusBarColorLight | 设置状态栏颜色,并且状态栏字符颜色变为深|支持6.0以上的普通机型
支持5.1以上的oppo机型
支持4.4以上的小米机型
支持4.4以上的魅族机型
9 | | setStatusBarTransparen | 设置状态栏沉浸式|支持4.4以上的所有机型
10 | | setStatusBarTransparenLight | 设置状态栏沉浸式,并且状态栏字符颜色变为深|支持6.0以上的普通机型
支持5.1以上的oppo机型
支持4.4以上的小米机型
支持4.4以上的魅族机型
11 | | setStatusBarLightStatus | 设置状态栏字符颜色状态|支持6.0以上的普通机型
支持5.1以上的oppo机型
支持所有小米机型
支持所有魅族机型
12 | | getStatusBarColor | 获取状态栏颜色|5.0以上所有机型可以正确获取,以下默认为黑色
13 | | getStatusBarHeight | 获取状态栏高度|支持所有机型
14 |
15 | ## 3、gradle
16 | add the dependency:
17 | ```gradle
18 | dependencies {
19 | ...
20 |
21 | implementation 'com.github.xubo.statusbarutils:StatusBarUtils:1.0.1'
22 | }
23 | ```
24 |
25 | ## 4、sample
26 |
27 | |示例|
28 | |:---:|
29 | | tab切换
|
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 28
5 | defaultConfig {
6 | applicationId "com.github.xubo.statusbarutils.sample"
7 | minSdkVersion 14
8 | targetSdkVersion 28
9 | versionCode 1
10 | versionName "1.0"
11 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
12 | }
13 | buildTypes {
14 | release {
15 | minifyEnabled false
16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17 | }
18 | }
19 | }
20 |
21 | dependencies {
22 | implementation fileTree(dir: 'libs', include: ['*.jar'])
23 | implementation 'com.android.support:appcompat-v7:28.0.0'
24 | implementation 'com.android.support.constraint:constraint-layout:1.1.3'
25 | testImplementation 'junit:junit:4.12'
26 | androidTestImplementation 'com.android.support.test:runner:1.0.2'
27 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
28 |
29 | implementation 'com.github.xubo.statusbarutils:StatusBarUtils:1.0.1'
30 | }
31 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/github/xubo/statusbarutils/sample/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.github.xubo.statusbarutils.sample;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumented test, which will execute on an Android device.
14 | * @see Testing documentation
15 | */
16 | @RunWith(AndroidJUnit4.class)
17 | public class ExampleInstrumentedTest {
18 | @Test
19 | public void useAppContext() {
20 | // Context of the app under test.
21 | Context appContext = InstrumentationRegistry.getTargetContext();
22 |
23 | assertEquals("com.github.xubo.statusbarutils.sample", appContext.getPackageName());
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/app/src/main/java/com/github/xubo/statusbarutils/sample/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.github.xubo.statusbarutils.sample;
2 |
3 | import android.content.Intent;
4 | import android.graphics.Color;
5 | import android.os.Bundle;
6 | import android.support.v7.app.ActionBar;
7 | import android.support.v7.app.AppCompatActivity;
8 | import android.view.View;
9 | import android.widget.Button;
10 |
11 | import com.github.xubo.statusbarutils.StatusBarUtils;
12 |
13 | public class MainActivity extends AppCompatActivity {
14 | private Button btn1;
15 | private Button btn2;
16 | private Button btn3;
17 | private Button btn4;
18 | private Button btn5;
19 |
20 | @Override
21 | protected void onCreate(Bundle savedInstanceState) {
22 | super.onCreate(savedInstanceState);
23 | setContentView(R.layout.activity_main);
24 | ActionBar actionBar = getSupportActionBar();
25 | actionBar.setTitle("状态栏工具类");
26 | StatusBarUtils.setStatusBarColorLight(this, Color.WHITE);
27 | btn1 = findViewById(R.id.btn1);
28 | btn2 = findViewById(R.id.btn2);
29 | btn3 = findViewById(R.id.btn3);
30 | btn4 = findViewById(R.id.btn4);
31 | btn5 = findViewById(R.id.btn5);
32 | btn1.setOnClickListener(new View.OnClickListener() {
33 | @Override
34 | public void onClick(View v) {
35 | Intent intent = new Intent(MainActivity.this, Page1Activity.class);
36 | startActivity(intent);
37 | }
38 | });
39 | btn2.setOnClickListener(new View.OnClickListener() {
40 | @Override
41 | public void onClick(View v) {
42 | Intent intent = new Intent(MainActivity.this, Page2Activity.class);
43 | startActivity(intent);
44 | }
45 | });
46 | btn3.setOnClickListener(new View.OnClickListener() {
47 | @Override
48 | public void onClick(View v) {
49 | Intent intent = new Intent(MainActivity.this, Page3Activity.class);
50 | startActivity(intent);
51 | }
52 | });
53 | btn4.setOnClickListener(new View.OnClickListener() {
54 | @Override
55 | public void onClick(View v) {
56 | Intent intent = new Intent(MainActivity.this, Page4Activity.class);
57 | startActivity(intent);
58 | }
59 | });
60 | btn5.setOnClickListener(new View.OnClickListener() {
61 | @Override
62 | public void onClick(View v) {
63 | Intent intent = new Intent(MainActivity.this, TabActivity.class);
64 | startActivity(intent);
65 | }
66 | });
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/app/src/main/java/com/github/xubo/statusbarutils/sample/MyScrollView.java:
--------------------------------------------------------------------------------
1 | package com.github.xubo.statusbarutils.sample;
2 |
3 | import android.content.Context;
4 | import android.util.AttributeSet;
5 | import android.view.View;
6 | import android.widget.ScrollView;
7 |
8 | /**
9 | * Author:xubo
10 | * Time:2019-04-22
11 | * Description:
12 | */
13 | public class MyScrollView extends ScrollView {
14 | private OnScrollListener listener;
15 |
16 | public MyScrollView(Context context) {
17 | super(context);
18 | }
19 |
20 | public MyScrollView(Context context, AttributeSet attrs) {
21 | super(context, attrs);
22 | }
23 |
24 | public MyScrollView(Context context, AttributeSet attrs, int defStyleAttr) {
25 | super(context, attrs, defStyleAttr);
26 | }
27 |
28 | @Override
29 | protected void onScrollChanged(int l, int t, int oldl, int oldt) {
30 | super.onScrollChanged(l, t, oldl, oldt);
31 | if (listener != null) {
32 | listener.scroll(t);
33 | }
34 | }
35 |
36 | public void setOnScrollListener(OnScrollListener listener) {
37 | this.listener = listener;
38 | }
39 |
40 | public interface OnScrollListener {
41 | void scroll(int y);
42 | }
43 |
44 | }
45 |
--------------------------------------------------------------------------------
/app/src/main/java/com/github/xubo/statusbarutils/sample/Page1Activity.java:
--------------------------------------------------------------------------------
1 | package com.github.xubo.statusbarutils.sample;
2 |
3 | import android.app.Activity;
4 | import android.graphics.Color;
5 | import android.os.Bundle;
6 | import android.support.annotation.Nullable;
7 |
8 | import com.github.xubo.statusbarutils.StatusBarUtils;
9 |
10 | /**
11 | * Author:xubo
12 | * Time:2019-04-22
13 | * Description:
14 | */
15 | public class Page1Activity extends Activity {
16 | @Override
17 | protected void onCreate(@Nullable Bundle savedInstanceState) {
18 | super.onCreate(savedInstanceState);
19 | setContentView(R.layout.activity_page1);
20 | StatusBarUtils.setStatusBarColor(this, Color.parseColor("#FFCC0000"));
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/app/src/main/java/com/github/xubo/statusbarutils/sample/Page2Activity.java:
--------------------------------------------------------------------------------
1 | package com.github.xubo.statusbarutils.sample;
2 |
3 | import android.app.Activity;
4 | import android.graphics.Color;
5 | import android.os.Bundle;
6 | import android.support.annotation.Nullable;
7 |
8 | import com.github.xubo.statusbarutils.StatusBarUtils;
9 |
10 | /**
11 | * Author:xubo
12 | * Time:2019-04-22
13 | * Description:
14 | */
15 | public class Page2Activity extends Activity {
16 | @Override
17 | protected void onCreate(@Nullable Bundle savedInstanceState) {
18 | super.onCreate(savedInstanceState);
19 | setContentView(R.layout.activity_page2);
20 | StatusBarUtils.setStatusBarColorLight(this, Color.WHITE);
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/app/src/main/java/com/github/xubo/statusbarutils/sample/Page3Activity.java:
--------------------------------------------------------------------------------
1 | package com.github.xubo.statusbarutils.sample;
2 |
3 | import android.app.Activity;
4 | import android.os.Bundle;
5 | import android.support.annotation.Nullable;
6 |
7 | import com.github.xubo.statusbarutils.StatusBarUtils;
8 |
9 | /**
10 | * Author:xubo
11 | * Time:2019-04-22
12 | * Description:
13 | */
14 | public class Page3Activity extends Activity {
15 | @Override
16 | protected void onCreate(@Nullable Bundle savedInstanceState) {
17 | super.onCreate(savedInstanceState);
18 | setContentView(R.layout.activity_page3);
19 | StatusBarUtils.setStatusBarTransparen(this);
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/app/src/main/java/com/github/xubo/statusbarutils/sample/Page4Activity.java:
--------------------------------------------------------------------------------
1 | package com.github.xubo.statusbarutils.sample;
2 |
3 | import android.app.Activity;
4 | import android.os.Bundle;
5 | import android.support.annotation.Nullable;
6 |
7 | import com.github.xubo.statusbarutils.StatusBarUtils;
8 |
9 | /**
10 | * Author:xubo
11 | * Time:2019-04-22
12 | * Description:
13 | */
14 | public class Page4Activity extends Activity {
15 | @Override
16 | protected void onCreate(@Nullable Bundle savedInstanceState) {
17 | super.onCreate(savedInstanceState);
18 | setContentView(R.layout.activity_page4);
19 | StatusBarUtils.setStatusBarTransparenLight(this);
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/app/src/main/java/com/github/xubo/statusbarutils/sample/Tab1Fragment.java:
--------------------------------------------------------------------------------
1 | package com.github.xubo.statusbarutils.sample;
2 |
3 | import android.app.Activity;
4 | import android.content.Context;
5 | import android.graphics.Color;
6 | import android.os.Bundle;
7 | import android.support.annotation.NonNull;
8 | import android.support.annotation.Nullable;
9 | import android.support.v4.app.Fragment;
10 | import android.view.LayoutInflater;
11 | import android.view.View;
12 | import android.view.ViewGroup;
13 |
14 | import com.github.xubo.statusbarutils.StatusBarUtils;
15 |
16 | /**
17 | * Author:xubo
18 | * Time:2019-04-22
19 | * Description:
20 | */
21 | public class Tab1Fragment extends Fragment {
22 | public static final String TAG = Tab1Fragment.class.getSimpleName();
23 | private View statusbar_view;
24 | private boolean isTransparen;
25 | private TabActivity activity;
26 |
27 | @Override
28 | public void onAttach(Context context) {
29 | super.onAttach(context);
30 | activity = (TabActivity) context;
31 | isTransparen = activity.isTransparen;
32 | }
33 |
34 | @Nullable
35 | @Override
36 | public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
37 | return inflater.inflate(R.layout.fragment_tab1, null);
38 | }
39 |
40 | @Override
41 | public void onActivityCreated(@Nullable Bundle savedInstanceState) {
42 | super.onActivityCreated(savedInstanceState);
43 | initView(getView());
44 | statusbar_view.getLayoutParams().height = StatusBarUtils.getStatusBarHeight(getContext());
45 | statusbar_view.setBackgroundColor(Color.WHITE);
46 | if (isTransparen) {
47 | statusbar_view.setVisibility(View.VISIBLE);
48 | } else {
49 | statusbar_view.setVisibility(View.GONE);
50 | }
51 | }
52 |
53 | private void initView(View view) {
54 | statusbar_view = view.findViewById(R.id.statusbar_view);
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/app/src/main/java/com/github/xubo/statusbarutils/sample/Tab2Fragment.java:
--------------------------------------------------------------------------------
1 | package com.github.xubo.statusbarutils.sample;
2 |
3 | import android.content.Context;
4 | import android.graphics.Color;
5 | import android.os.Bundle;
6 | import android.support.annotation.NonNull;
7 | import android.support.annotation.Nullable;
8 | import android.support.v4.app.Fragment;
9 | import android.view.LayoutInflater;
10 | import android.view.View;
11 | import android.view.ViewGroup;
12 | import android.widget.LinearLayout;
13 |
14 | import com.github.xubo.statusbarutils.StatusBarUtils;
15 |
16 | /**
17 | * Author:xubo
18 | * Time:2019-04-22
19 | * Description:
20 | */
21 | public class Tab2Fragment extends Fragment {
22 | public static final String TAG = Tab2Fragment.class.getSimpleName();
23 | private View tab2_statusbar_view;
24 | private LinearLayout tab_title_ll;
25 | private MyScrollView tab2_sv;
26 | private boolean isTransparen;
27 | private TabActivity activity;
28 | private boolean isLightStatus;
29 |
30 | @Override
31 | public void onAttach(Context context) {
32 | super.onAttach(context);
33 | activity = (TabActivity) context;
34 | isTransparen = activity.isTransparen;
35 | }
36 |
37 | @Nullable
38 | @Override
39 | public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
40 | return inflater.inflate(R.layout.fragment_tab2, null);
41 | }
42 |
43 | @Override
44 | public void onActivityCreated(@Nullable Bundle savedInstanceState) {
45 | super.onActivityCreated(savedInstanceState);
46 | initView(getView());
47 | tab2_statusbar_view.getLayoutParams().height = StatusBarUtils.getStatusBarHeight(getContext());
48 | tab2_statusbar_view.setBackgroundColor(Color.WHITE);
49 | if (isTransparen) {
50 | tab2_statusbar_view.setVisibility(View.VISIBLE);
51 | } else {
52 | tab2_statusbar_view.setVisibility(View.GONE);
53 | }
54 | tab_title_ll.measure(0, 0);
55 | final float height = tab_title_ll.getMeasuredHeight();
56 | tab_title_ll.setAlpha(0);
57 |
58 | tab2_sv.setOnScrollListener(new MyScrollView.OnScrollListener() {
59 | @Override
60 | public void scroll(int y) {
61 | boolean status = isLightStatus;
62 | float alpha = 1.0f;
63 | if (y < height) {
64 | alpha = y / height;
65 | }
66 | if (alpha < 0.5f) {
67 | status = false;
68 | } else {
69 | status = true;
70 | }
71 | tab_title_ll.setAlpha(alpha);
72 | if (status != isLightStatus) {
73 | isLightStatus = status;
74 | StatusBarUtils.setStatusBarLightStatus(activity, isLightStatus);
75 | }
76 | }
77 | });
78 | }
79 |
80 | public boolean isStatusBarLightStatus() {
81 | return isLightStatus;
82 | }
83 |
84 | private void initView(View view) {
85 | tab2_statusbar_view = view.findViewById(R.id.tab2_statusbar_view);
86 | tab2_sv = view.findViewById(R.id.tab2_sv);
87 | tab_title_ll = view.findViewById(R.id.tab_title_ll);
88 | }
89 | }
90 |
--------------------------------------------------------------------------------
/app/src/main/java/com/github/xubo/statusbarutils/sample/TabActivity.java:
--------------------------------------------------------------------------------
1 | package com.github.xubo.statusbarutils.sample;
2 |
3 | import android.os.Bundle;
4 | import android.support.annotation.Nullable;
5 | import android.support.v4.app.Fragment;
6 | import android.support.v4.app.FragmentManager;
7 | import android.support.v4.app.FragmentTransaction;
8 | import android.support.v7.app.ActionBar;
9 | import android.support.v7.app.AppCompatActivity;
10 | import android.widget.RadioGroup;
11 |
12 | import com.github.xubo.statusbarutils.StatusBarUtils;
13 |
14 | import java.util.List;
15 |
16 | /**
17 | * Author:xubo
18 | * Time:2019-04-22
19 | * Description:
20 | */
21 | public class TabActivity extends AppCompatActivity {
22 | private FragmentManager fragmentManager;
23 | private RadioGroup tab_rg;
24 | public boolean isTransparen;
25 |
26 | @Override
27 | protected void onCreate(@Nullable Bundle savedInstanceState) {
28 | super.onCreate(savedInstanceState);
29 | setContentView(R.layout.activity_tab);
30 | getSupportActionBar().hide();
31 | isTransparen = StatusBarUtils.setStatusBarTransparenLight(this);
32 | fragmentManager = getSupportFragmentManager();
33 |
34 | tab_rg = findViewById(R.id.tab_rg);
35 | setContent(Tab1Fragment.TAG);
36 | listener();
37 | }
38 |
39 | private void listener() {
40 | tab_rg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
41 | @Override
42 | public void onCheckedChanged(RadioGroup group, int checkedId) {
43 | switch (checkedId) {
44 | case R.id.tab1_rb:
45 | setContent(Tab1Fragment.TAG);
46 | break;
47 | case R.id.tab2_rb:
48 | setContent(Tab2Fragment.TAG);
49 | break;
50 | }
51 | }
52 | });
53 | }
54 |
55 | private void setContent(String fragmentTag) {
56 | FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
57 | List fragments = fragmentManager.getFragments();
58 | hideFragments(fragments, fragmentTransaction, fragmentTag);
59 | if (Tab1Fragment.TAG.equals(fragmentTag)) {
60 | Tab1Fragment fragment = (Tab1Fragment) fragmentManager.findFragmentByTag(Tab1Fragment.TAG);
61 | if (fragment == null) {
62 | fragment = new Tab1Fragment();
63 | fragmentTransaction.add(R.id.tab_fl, fragment, fragmentTag);
64 | } else {
65 | fragmentTransaction.show(fragment);
66 | }
67 | //字符颜色变深
68 | StatusBarUtils.setStatusBarLightStatus(TabActivity.this, true);
69 | } else if (Tab2Fragment.TAG.equals(fragmentTag)) {
70 | Tab2Fragment fragment = (Tab2Fragment) fragmentManager.findFragmentByTag(Tab2Fragment.TAG);
71 | if (fragment == null) {
72 | fragment = new Tab2Fragment();
73 | fragmentTransaction.add(R.id.tab_fl, fragment, fragmentTag);
74 | } else {
75 | fragmentTransaction.show(fragment);
76 | }
77 | StatusBarUtils.setStatusBarLightStatus(TabActivity.this, fragment.isStatusBarLightStatus());
78 | }
79 | fragmentTransaction.commitAllowingStateLoss();
80 | }
81 |
82 | private void hideFragments(List fragments, FragmentTransaction fragmentTransaction, String showTag) {
83 | if (fragments == null || fragments.size() == 0) {
84 | return;
85 | }
86 | for (Fragment fragment : fragments) {
87 | String tag = fragment.getTag();
88 | if (!showTag.equals(tag)) {
89 | fragmentTransaction.hide(fragment);
90 | }
91 | }
92 | }
93 | }
94 |
--------------------------------------------------------------------------------
/app/src/main/res/color/main_radio_color.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/img2.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pirrip90/StatusBarUtils/d8e767491fe3c9e513c2dff2a8c193b733d0eb98/app/src/main/res/drawable-xhdpi/img2.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/img1.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pirrip90/StatusBarUtils/d8e767491fe3c9e513c2dff2a8c193b733d0eb98/app/src/main/res/drawable-xxhdpi/img1.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
11 |
16 |
21 |
26 |
31 |
36 |
41 |
46 |
51 |
56 |
61 |
66 |
71 |
76 |
81 |
86 |
91 |
96 |
101 |
106 |
111 |
116 |
121 |
126 |
131 |
136 |
141 |
146 |
151 |
156 |
161 |
166 |
171 |
172 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
12 |
13 |
21 |
22 |
29 |
30 |
35 |
36 |
41 |
42 |
43 |
50 |
51 |
56 |
57 |
62 |
63 |
64 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_page1.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
20 |
21 |
29 |
30 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_page2.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
20 |
21 |
29 |
30 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_page3.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
13 |
14 |
22 |
23 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_page4.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
14 |
15 |
23 |
24 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_tab.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
13 |
14 |
18 |
19 |
25 |
26 |
38 |
39 |
50 |
51 |
52 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_tab1.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
14 |
15 |
26 |
27 |
31 |
32 |
40 |
41 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_tab2.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
14 |
15 |
19 |
20 |
24 |
25 |
29 |
30 |
34 |
35 |
36 |
40 |
41 |
45 |
46 |
47 |
51 |
52 |
60 |
61 |
62 |
63 |
68 |
69 |
74 |
75 |
86 |
87 |
91 |
92 |
93 |
94 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pirrip90/StatusBarUtils/d8e767491fe3c9e513c2dff2a8c193b733d0eb98/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pirrip90/StatusBarUtils/d8e767491fe3c9e513c2dff2a8c193b733d0eb98/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pirrip90/StatusBarUtils/d8e767491fe3c9e513c2dff2a8c193b733d0eb98/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pirrip90/StatusBarUtils/d8e767491fe3c9e513c2dff2a8c193b733d0eb98/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pirrip90/StatusBarUtils/d8e767491fe3c9e513c2dff2a8c193b733d0eb98/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pirrip90/StatusBarUtils/d8e767491fe3c9e513c2dff2a8c193b733d0eb98/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pirrip90/StatusBarUtils/d8e767491fe3c9e513c2dff2a8c193b733d0eb98/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pirrip90/StatusBarUtils/d8e767491fe3c9e513c2dff2a8c193b733d0eb98/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pirrip90/StatusBarUtils/d8e767491fe3c9e513c2dff2a8c193b733d0eb98/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pirrip90/StatusBarUtils/d8e767491fe3c9e513c2dff2a8c193b733d0eb98/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | StatusBarUtils
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/test/java/com/github/xubo/statusbarutils/sample/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.github.xubo.statusbarutils.sample;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | * @see Testing documentation
10 | */
11 | public class ExampleUnitTest {
12 | @Test
13 | public void addition_isCorrect() {
14 | assertEquals(4, 2 + 2);
15 | }
16 | }
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 |
5 | repositories {
6 | google()
7 | jcenter()
8 | }
9 | dependencies {
10 | classpath 'com.android.tools.build:gradle:3.1.3'
11 | classpath 'com.novoda:bintray-release:0.8.1'
12 |
13 | // NOTE: Do not place your application dependencies here; they belong
14 | // in the individual module build.gradle files
15 | }
16 | }
17 |
18 | allprojects {
19 | repositories {
20 | google()
21 | jcenter()
22 | }
23 | }
24 |
25 | task clean(type: Delete) {
26 | delete rootProject.buildDir
27 | }
28 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pirrip90/StatusBarUtils/d8e767491fe3c9e513c2dff2a8c193b733d0eb98/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Sun Apr 21 16:54:02 CST 2019
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/screen/screen.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pirrip90/StatusBarUtils/d8e767491fe3c9e513c2dff2a8c193b733d0eb98/screen/screen.gif
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':statusbarutils'
2 |
--------------------------------------------------------------------------------
/statusbarutils/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 | publish.gradle
--------------------------------------------------------------------------------
/statusbarutils/build.gradle:
--------------------------------------------------------------------------------
1 | apply {
2 | plugin 'com.android.library'
3 | // from 'publish.gradle'
4 | from 'version.gradle'
5 | }
6 |
7 | android {
8 | compileSdkVersion 23
9 |
10 |
11 |
12 | defaultConfig {
13 | minSdkVersion 14
14 | targetSdkVersion 23
15 | versionCode versionCode
16 | versionName versionName
17 |
18 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
19 |
20 | }
21 |
22 | buildTypes {
23 | release {
24 | minifyEnabled false
25 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
26 | }
27 | }
28 |
29 | }
30 |
31 | dependencies {
32 | implementation fileTree(dir: 'libs', include: ['*.jar'])
33 |
34 | implementation 'com.android.support:appcompat-v7:23.0.0'
35 | testImplementation 'junit:junit:4.12'
36 | androidTestImplementation 'com.android.support.test:runner:1.0.2'
37 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
38 |
39 | api 'com.readystatesoftware.systembartint:systembartint:1.0.3'
40 | }
41 |
--------------------------------------------------------------------------------
/statusbarutils/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/statusbarutils/src/androidTest/java/com/github/xubo/statusbarutils/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.github.xubo.statusbarutils;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumented test, which will execute on an Android device.
14 | * @see Testing documentation
15 | */
16 | @RunWith(AndroidJUnit4.class)
17 | public class ExampleInstrumentedTest {
18 | @Test
19 | public void useAppContext() {
20 | // Context of the app under test.
21 | Context appContext = InstrumentationRegistry.getTargetContext();
22 |
23 | assertEquals("com.github.xubo.statusbarutils.test", appContext.getPackageName());
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/statusbarutils/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
--------------------------------------------------------------------------------
/statusbarutils/src/main/java/com/github/xubo/statusbarutils/FlymeStatusbarColorUtils.java:
--------------------------------------------------------------------------------
1 | package com.github.xubo.statusbarutils;
2 |
3 | import android.app.Activity;
4 | import android.os.Build;
5 | import android.view.View;
6 | import android.view.Window;
7 | import android.view.WindowManager;
8 |
9 | import java.lang.reflect.Field;
10 | import java.lang.reflect.InvocationTargetException;
11 | import java.lang.reflect.Method;
12 |
13 |
14 | public class FlymeStatusbarColorUtils {
15 | private static Method mSetStatusBarColorIcon;
16 | private static Method mSetStatusBarDarkIcon;
17 | private static Field mStatusBarColorFiled;
18 | private static int SYSTEM_UI_FLAG_LIGHT_STATUS_BAR = 0;
19 |
20 | static {
21 | try {
22 | mSetStatusBarColorIcon = Activity.class.getMethod("setStatusBarDarkIcon", int.class);
23 | } catch (NoSuchMethodException e) {
24 | e.printStackTrace();
25 | }
26 | try {
27 | mSetStatusBarDarkIcon = Activity.class.getMethod("setStatusBarDarkIcon", boolean.class);
28 | } catch (NoSuchMethodException e) {
29 | e.printStackTrace();
30 | }
31 | try {
32 | mStatusBarColorFiled = WindowManager.LayoutParams.class.getField("statusBarColor");
33 | } catch (NoSuchFieldException e) {
34 | e.printStackTrace();
35 | }
36 | try {
37 | Field field = View.class.getField("SYSTEM_UI_FLAG_LIGHT_STATUS_BAR");
38 | SYSTEM_UI_FLAG_LIGHT_STATUS_BAR = field.getInt(null);
39 | } catch (NoSuchFieldException e) {
40 | e.printStackTrace();
41 | } catch (IllegalAccessException e) {
42 | e.printStackTrace();
43 | }
44 | }
45 |
46 | /**
47 | * 判断颜色是否偏黑色
48 | * @param color 颜色
49 | * @param level 级别
50 | * @return
51 | */
52 | public static boolean isBlackColor(int color, int level) {
53 | int grey = toGrey(color);
54 | return grey < level;
55 | }
56 |
57 | /**
58 | * 颜色转换成灰度值
59 | * @param rgb 颜色
60 | * @return 灰度值
61 | */
62 | public static int toGrey(int rgb) {
63 | int blue = rgb & 0x000000FF;
64 | int green = (rgb & 0x0000FF00) >> 8;
65 | int red = (rgb & 0x00FF0000) >> 16;
66 | return (red * 38 + green * 75 + blue * 15) >> 7;
67 | }
68 |
69 | /**
70 | * 设置状态栏字体图标颜色
71 | * @param activity 当前activity
72 | * @param color 颜色
73 | */
74 | public static void setStatusBarDarkIcon(Activity activity, int color) {
75 | if (mSetStatusBarColorIcon != null) {
76 | try {
77 | mSetStatusBarColorIcon.invoke(activity, color);
78 | } catch (IllegalAccessException e) {
79 | e.printStackTrace();
80 | } catch (InvocationTargetException e) {
81 | e.printStackTrace();
82 | }
83 | } else {
84 | boolean whiteColor = isBlackColor(color, 50);
85 | if (mStatusBarColorFiled != null) {
86 | setStatusBarDarkIcon(activity, whiteColor, whiteColor);
87 | setStatusBarDarkIcon(activity.getWindow(), color);
88 | } else {
89 | setStatusBarDarkIcon(activity, whiteColor);
90 | }
91 | }
92 | }
93 |
94 | /**
95 | * 设置状态栏字体图标颜色(只限全屏非activity情况)
96 | * @param window 当前窗口
97 | * @param color 颜色
98 | */
99 | public static void setStatusBarDarkIcon(Window window, int color) {
100 | try {
101 | setStatusBarColor(window, color);
102 | if (Build.VERSION.SDK_INT > 22) {
103 | setStatusBarDarkIcon(window.getDecorView(), true);
104 | }
105 | } catch (Exception e) {
106 | e.printStackTrace();
107 | }
108 | }
109 |
110 | /**
111 | * 设置状态栏字体图标颜色
112 | * @param activity 当前activity
113 | * @param dark 是否深色 true为深色 false 为白色
114 | */
115 | public static void setStatusBarDarkIcon(Activity activity, boolean dark) {
116 | setStatusBarDarkIcon(activity, dark, true);
117 | }
118 |
119 | private static boolean changeMeizuFlag(WindowManager.LayoutParams winParams, String flagName, boolean on) {
120 | try {
121 | Field f = winParams.getClass().getDeclaredField(flagName);
122 | f.setAccessible(true);
123 | int bits = f.getInt(winParams);
124 | Field f2 = winParams.getClass().getDeclaredField("meizuFlags");
125 | f2.setAccessible(true);
126 | int meizuFlags = f2.getInt(winParams);
127 | int oldFlags = meizuFlags;
128 | if (on) {
129 | meizuFlags |= bits;
130 | } else {
131 | meizuFlags &= ~bits;
132 | }
133 | if (oldFlags != meizuFlags) {
134 | f2.setInt(winParams, meizuFlags);
135 | return true;
136 | }
137 | } catch (NoSuchFieldException e) {
138 | e.printStackTrace();
139 | } catch (IllegalAccessException e) {
140 | e.printStackTrace();
141 | } catch (IllegalArgumentException e) {
142 | e.printStackTrace();
143 | } catch (Throwable e) {
144 | e.printStackTrace();
145 | }
146 | return false;
147 | }
148 |
149 | /**
150 | * 设置状态栏颜色
151 | * @param view
152 | * @param dark
153 | */
154 | private static void setStatusBarDarkIcon(View view, boolean dark) {
155 | int oldVis = view.getSystemUiVisibility();
156 | int newVis = oldVis;
157 | if (dark) {
158 | newVis |= SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
159 | } else {
160 | newVis &= ~SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
161 | }
162 | if (newVis != oldVis) {
163 | view.setSystemUiVisibility(newVis);
164 | }
165 | }
166 |
167 | /**
168 | * 设置状态栏颜色
169 | * @param window
170 | * @param color
171 | */
172 | private static void setStatusBarColor(Window window, int color) {
173 | WindowManager.LayoutParams winParams = window.getAttributes();
174 | if (mStatusBarColorFiled != null) {
175 | try {
176 | int oldColor = mStatusBarColorFiled.getInt(winParams);
177 | if (oldColor != color) {
178 | mStatusBarColorFiled.set(winParams, color);
179 | window.setAttributes(winParams);
180 | }
181 | } catch (IllegalAccessException e) {
182 | e.printStackTrace();
183 | }
184 | }
185 | }
186 |
187 | /**
188 | * 设置状态栏字体图标颜色(只限全屏非activity情况)
189 | * @param window 当前窗口
190 | * @param dark 是否深色 true为深色 false 为白色
191 | */
192 | public static void setStatusBarDarkIcon(Window window, boolean dark) {
193 | if (Build.VERSION.SDK_INT < 23) {
194 | changeMeizuFlag(window.getAttributes(), "MEIZU_FLAG_DARK_STATUS_BAR_ICON", dark);
195 | } else {
196 | View decorView = window.getDecorView();
197 | if (decorView != null) {
198 | setStatusBarDarkIcon(decorView, dark);
199 | setStatusBarColor(window, 0);
200 | }
201 | }
202 | }
203 |
204 | private static void setStatusBarDarkIcon(Activity activity, boolean dark, boolean flag) {
205 | if (mSetStatusBarDarkIcon != null) {
206 | try {
207 | mSetStatusBarDarkIcon.invoke(activity, dark);
208 | } catch (IllegalAccessException e) {
209 | e.printStackTrace();
210 | } catch (InvocationTargetException e) {
211 | e.printStackTrace();
212 | }
213 | } else {
214 | if (flag) {
215 | setStatusBarDarkIcon(activity.getWindow(), dark);
216 | }
217 | }
218 | }
219 | }
220 |
--------------------------------------------------------------------------------
/statusbarutils/src/main/java/com/github/xubo/statusbarutils/OSInfo.java:
--------------------------------------------------------------------------------
1 | package com.github.xubo.statusbarutils;
2 |
3 | import android.content.Context;
4 | import android.content.SharedPreferences;
5 | import android.os.Build;
6 | import android.text.TextUtils;
7 |
8 | import java.io.BufferedReader;
9 | import java.io.IOException;
10 | import java.io.InputStreamReader;
11 |
12 | /**
13 | * Author:xubo
14 | * Time:2019-04-21
15 | * Description:
16 | */
17 | public class OSInfo {
18 | public enum OSType {
19 | OS_TYPE_OTHER(0),
20 | OS_TYPE_EMUI(1),
21 | OS_TYPE_MIUI(2),
22 | OS_TYPE_FLYME(3),
23 | OS_TYPE_COLOR(4),
24 | OS_TYPE_FUNTOUCH(5);
25 |
26 | private final int value;
27 |
28 | OSType(int value) {
29 | this.value = value;
30 | }
31 | }
32 |
33 | /** SharedPreferences标识 */
34 | public static final String OS_SP = "com_github_xubo_statusbarutils_os_sp";
35 |
36 | /** MIUI标识(小米) */
37 | private static final String KEY_VERSION_MIUI = "ro.miui.ui.version.name";
38 | /** EMUI标识(华为) */
39 | private static final String KEY_VERSION_EMUI = "ro.build.version.emui";
40 | /** Flyme标识(魅族) */
41 | public static final String KEY_VERSION_FLYME = "ro.meizu.setupwizard.flyme";
42 | /** color标识(oppo) */
43 | private static final String KEY_VERSION_COLOR = "ro.build.version.opporom";
44 | /** color标识(funtouch) */
45 | private static final String KEY_VERSION_FUNTOUCH = "ro.vivo.os.version";
46 |
47 | public static OSType getRomType(Context context) {
48 | SharedPreferences sharedPreferences = context.getSharedPreferences(OS_SP, Context.MODE_PRIVATE);
49 | int osTypeValue = sharedPreferences.getInt("os_type", -1);
50 | if (osTypeValue == -1) {
51 | String display = Build.DISPLAY;
52 | if (display.toUpperCase().contains("FLYME")) {
53 | sharedPreferences.edit().putInt("os_type", OSType.OS_TYPE_FLYME.value).commit();
54 | return OSType.OS_TYPE_FLYME;
55 | } else {
56 | if (!TextUtils.isEmpty(getProp(KEY_VERSION_MIUI))) {
57 | sharedPreferences.edit().putInt("os_type", OSType.OS_TYPE_MIUI.value).commit();
58 | return OSType.OS_TYPE_MIUI;
59 | } else if (!TextUtils.isEmpty(getProp(KEY_VERSION_EMUI))) {
60 | sharedPreferences.edit().putInt("os_type", OSType.OS_TYPE_EMUI.value).commit();
61 | return OSType.OS_TYPE_EMUI;
62 | } else if (!TextUtils.isEmpty(getProp(KEY_VERSION_FLYME))) {
63 | sharedPreferences.edit().putInt("os_type", OSType.OS_TYPE_FLYME.value).commit();
64 | return OSType.OS_TYPE_FLYME;
65 | } else if (!TextUtils.isEmpty(getProp(KEY_VERSION_COLOR))) {
66 | sharedPreferences.edit().putInt("os_type", OSType.OS_TYPE_COLOR.value).commit();
67 | return OSType.OS_TYPE_COLOR;
68 | } else if (!TextUtils.isEmpty(getProp(KEY_VERSION_FUNTOUCH))) {
69 | sharedPreferences.edit().putInt("os_type", OSType.OS_TYPE_FUNTOUCH.value).commit();
70 | return OSType.OS_TYPE_FUNTOUCH;
71 | } else {
72 | sharedPreferences.edit().putInt("os_type", OSType.OS_TYPE_OTHER.value).commit();
73 | return OSType.OS_TYPE_OTHER;
74 | }
75 | }
76 | } else {
77 | OSType osType;
78 | switch (osTypeValue) {
79 | case 0:
80 | osType = OSType.OS_TYPE_OTHER;
81 | break;
82 | case 1:
83 | osType = OSType.OS_TYPE_EMUI;
84 | break;
85 | case 2:
86 | osType = OSType.OS_TYPE_MIUI;
87 | break;
88 | case 3:
89 | osType = OSType.OS_TYPE_FLYME;
90 | break;
91 | case 4:
92 | osType = OSType.OS_TYPE_COLOR;
93 | break;
94 | case 5:
95 | osType = OSType.OS_TYPE_FUNTOUCH;
96 | break;
97 | default:
98 | osType = OSType.OS_TYPE_OTHER;
99 | break;
100 | }
101 | return osType;
102 | }
103 | }
104 |
105 | public static String getProp(String name) {
106 | String line;
107 | BufferedReader input = null;
108 | try {
109 | Process p = Runtime.getRuntime().exec("getprop " + name);
110 | input = new BufferedReader(new InputStreamReader(p.getInputStream()), 1024);
111 | line = input.readLine();
112 | input.close();
113 | } catch (IOException ex) {
114 | return null;
115 | } finally {
116 | if (input != null) {
117 | try {
118 | input.close();
119 | } catch (IOException e) {
120 | e.printStackTrace();
121 | }
122 | }
123 | }
124 | return line;
125 | }
126 | }
127 |
--------------------------------------------------------------------------------
/statusbarutils/src/main/java/com/github/xubo/statusbarutils/StatusBarUtils.java:
--------------------------------------------------------------------------------
1 | package com.github.xubo.statusbarutils;
2 |
3 | import android.app.Activity;
4 | import android.content.Context;
5 | import android.graphics.Color;
6 | import android.os.Build;
7 | import android.support.annotation.ColorInt;
8 | import android.support.v7.app.AppCompatActivity;
9 | import android.util.TypedValue;
10 | import android.view.View;
11 | import android.view.Window;
12 | import android.view.WindowManager;
13 |
14 | import com.readystatesoftware.systembartint.SystemBarTintManager;
15 |
16 | import java.lang.reflect.Field;
17 | import java.lang.reflect.Method;
18 |
19 | /**
20 | * Author:xubo
21 | * Time:2019-04-21
22 | * Description:
23 | */
24 | public class StatusBarUtils {
25 | /** oppo coloros 5.1系统该flag标记状态栏字符变深 */
26 | private static final int SYSTEM_UI_FLAG_OP_STATUS_BAR_TINT = 0x00000010;
27 |
28 | /**
29 | * 设置状态栏颜色
30 | * 支持4.4以上的所有机型
31 | * @param activity
32 | * @param color
33 | */
34 | public static void setStatusBarColor(Activity activity, @ColorInt int color) {
35 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
36 | Window window = activity.getWindow();
37 | window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
38 | window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
39 | window.setStatusBarColor(color);
40 | } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
41 | Window window = activity.getWindow();
42 | WindowManager.LayoutParams winParams = window.getAttributes();
43 | int bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;
44 | winParams.flags |= bits;
45 | window.setAttributes(winParams);
46 | View decorView = window.getDecorView();
47 | SystemBarTintManager tintManager = new SystemBarTintManager(activity);
48 | tintManager.setStatusBarTintEnabled(true);
49 | tintManager.setStatusBarTintColor(color);
50 | View contentView = decorView.findViewById(android.R.id.content);
51 | boolean withActionBar = false;
52 | if (activity instanceof AppCompatActivity) {
53 | AppCompatActivity appCompatActivity = (AppCompatActivity) activity;
54 | withActionBar = appCompatActivity.getSupportActionBar().isShowing();
55 | }
56 | contentView.setPadding(0,
57 | tintManager.getConfig().getPixelInsetTop(withActionBar),
58 | tintManager.getConfig().getPixelInsetRight(),
59 | tintManager.getConfig().getPixelInsetBottom());
60 | }
61 | }
62 |
63 | /**
64 | * 设置状态栏颜色,并且状态栏字符颜色变为深
65 | * 支持6.0以上的普通机型
66 | * 支持5.1以上的oppo机型
67 | * 支持4.4以上的小米机型
68 | * 支持4.4以上的魅族机型
69 | * @param activity
70 | * @param color
71 | */
72 | public static void setStatusBarColorLight(Activity activity, @ColorInt int color) {
73 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
74 | OSInfo.OSType osType = OSInfo.getRomType(activity);
75 | Window window = activity.getWindow();
76 | View decorView = window.getDecorView();
77 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
78 | decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
79 | window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
80 | window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
81 | window.setStatusBarColor(color);
82 | } else if (osType == OSInfo.OSType.OS_TYPE_MIUI) {
83 | Class extends Window> clazz = window.getClass();
84 | try {
85 | int darkModeFlag = 0;
86 | Class> layoutParams = Class.forName("android.view.MiuiWindowManager$LayoutParams");
87 | Field field = layoutParams.getField("EXTRA_FLAG_STATUS_BAR_DARK_MODE");
88 | darkModeFlag = field.getInt(layoutParams);
89 | Method extraFlagField = clazz.getMethod("setExtraFlags", int.class, int.class);
90 | extraFlagField.invoke(window, true ? darkModeFlag : 0, darkModeFlag);
91 | } catch (Exception e) {
92 | e.printStackTrace();
93 | }
94 | window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
95 | window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
96 | window.setStatusBarColor(color);
97 | } else if (osType == OSInfo.OSType.OS_TYPE_FLYME) {
98 | FlymeStatusbarColorUtils.setStatusBarDarkIcon(activity, true);
99 | window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
100 | window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
101 | window.setStatusBarColor(color);
102 | } else if (osType == OSInfo.OSType.OS_TYPE_COLOR && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
103 | decorView.setSystemUiVisibility(SYSTEM_UI_FLAG_OP_STATUS_BAR_TINT);
104 | window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
105 | window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
106 | window.setStatusBarColor(color);
107 | }
108 | } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
109 | OSInfo.OSType osType = OSInfo.getRomType(activity);
110 | Window window = activity.getWindow();
111 | View decorView = window.getDecorView();
112 | if (osType == OSInfo.OSType.OS_TYPE_MIUI) {
113 | Class extends Window> clazz = window.getClass();
114 | try {
115 | int darkModeFlag = 0;
116 | Class> layoutParams = Class.forName("android.view.MiuiWindowManager$LayoutParams");
117 | Field field = layoutParams.getField("EXTRA_FLAG_STATUS_BAR_DARK_MODE");
118 | darkModeFlag = field.getInt(layoutParams);
119 | Method extraFlagField = clazz.getMethod("setExtraFlags", int.class, int.class);
120 | extraFlagField.invoke(window, true ? darkModeFlag : 0, darkModeFlag);
121 | } catch (Exception e) {
122 | e.printStackTrace();
123 | }
124 | WindowManager.LayoutParams winParams = window.getAttributes();
125 | int bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;
126 | winParams.flags |= bits;
127 | window.setAttributes(winParams);
128 | SystemBarTintManager tintManager = new SystemBarTintManager(activity);
129 | tintManager.setStatusBarTintEnabled(true);
130 | tintManager.setStatusBarTintColor(color);
131 | View contentView = decorView.findViewById(android.R.id.content);
132 | boolean withActionBar = false;
133 | if (activity instanceof AppCompatActivity) {
134 | AppCompatActivity appCompatActivity = (AppCompatActivity) activity;
135 | withActionBar = appCompatActivity.getSupportActionBar().isShowing();
136 | }
137 | contentView.setPadding(0,
138 | tintManager.getConfig().getPixelInsetTop(withActionBar),
139 | tintManager.getConfig().getPixelInsetRight(),
140 | tintManager.getConfig().getPixelInsetBottom());
141 | } else if (osType == OSInfo.OSType.OS_TYPE_FLYME) {
142 | FlymeStatusbarColorUtils.setStatusBarDarkIcon(activity, true);
143 | WindowManager.LayoutParams winParams = window.getAttributes();
144 | int bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;
145 | winParams.flags |= bits;
146 | window.setAttributes(winParams);
147 | SystemBarTintManager tintManager = new SystemBarTintManager(activity);
148 | tintManager.setStatusBarTintEnabled(true);
149 | tintManager.setStatusBarTintColor(color);
150 | View contentView = decorView.findViewById(android.R.id.content);
151 | boolean withActionBar = false;
152 | if (activity instanceof AppCompatActivity) {
153 | AppCompatActivity appCompatActivity = (AppCompatActivity) activity;
154 | withActionBar = appCompatActivity.getSupportActionBar().isShowing();
155 | }
156 | contentView.setPadding(0,
157 | tintManager.getConfig().getPixelInsetTop(withActionBar),
158 | tintManager.getConfig().getPixelInsetRight(),
159 | tintManager.getConfig().getPixelInsetBottom());
160 | }
161 | }
162 | }
163 |
164 | /**
165 | * 设置状态栏沉浸式
166 | * 支持4.4以上的所有机型
167 | * @param activity
168 | * @return 设置成功true, 设置失败false
169 | */
170 | public static boolean setStatusBarTransparen(Activity activity) {
171 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
172 | Window window = activity.getWindow();
173 | window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
174 | window.setStatusBarColor(Color.TRANSPARENT);
175 | return true;
176 | } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
177 | Window window = activity.getWindow();
178 | WindowManager.LayoutParams winParams = window.getAttributes();
179 | int bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;
180 | winParams.flags |= bits;
181 | window.setAttributes(winParams);
182 | return true;
183 | }
184 | return false;
185 | }
186 |
187 | /**
188 | * 设置状态栏沉浸式,并且状态栏字符颜色变为深
189 | * 支持6.0以上的普通机型
190 | * 支持5.1以上的oppo机型
191 | * 支持4.4以上的小米机型
192 | * 支持4.4以上的魅族机型
193 | * @param activity
194 | * @return 设置成功true, 设置失败false
195 | */
196 | public static boolean setStatusBarTransparenLight(Activity activity) {
197 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
198 | OSInfo.OSType osType = OSInfo.getRomType(activity);
199 | Window window = activity.getWindow();
200 | View decorView = window.getDecorView();
201 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
202 | decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
203 | window.setStatusBarColor(Color.TRANSPARENT);
204 | return true;
205 | } else if (osType == OSInfo.OSType.OS_TYPE_MIUI) {
206 | decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
207 | window.setStatusBarColor(Color.TRANSPARENT);
208 | Class extends Window> clazz = window.getClass();
209 | try {
210 | int darkModeFlag = 0;
211 | Class> layoutParams = Class.forName("android.view.MiuiWindowManager$LayoutParams");
212 | Field field = layoutParams.getField("EXTRA_FLAG_STATUS_BAR_DARK_MODE");
213 | darkModeFlag = field.getInt(layoutParams);
214 | Method extraFlagField = clazz.getMethod("setExtraFlags", int.class, int.class);
215 | extraFlagField.invoke(window, true ? darkModeFlag : 0, darkModeFlag);
216 | } catch (Exception e) {
217 | e.printStackTrace();
218 | }
219 | return true;
220 | } else if (osType == OSInfo.OSType.OS_TYPE_FLYME) {
221 | decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
222 | window.setStatusBarColor(Color.TRANSPARENT);
223 | FlymeStatusbarColorUtils.setStatusBarDarkIcon(activity, true);
224 | return true;
225 | } else if (osType == OSInfo.OSType.OS_TYPE_COLOR && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
226 | decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | SYSTEM_UI_FLAG_OP_STATUS_BAR_TINT);
227 | window.setStatusBarColor(Color.TRANSPARENT);
228 | return true;
229 | }
230 | } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
231 | OSInfo.OSType osType = OSInfo.getRomType(activity);
232 | Window window = activity.getWindow();
233 | if (osType == OSInfo.OSType.OS_TYPE_MIUI) {
234 | Class extends Window> clazz = window.getClass();
235 | try {
236 | int darkModeFlag = 0;
237 | Class> layoutParams = Class.forName("android.view.MiuiWindowManager$LayoutParams");
238 | Field field = layoutParams.getField("EXTRA_FLAG_STATUS_BAR_DARK_MODE");
239 | darkModeFlag = field.getInt(layoutParams);
240 | Method extraFlagField = clazz.getMethod("setExtraFlags", int.class, int.class);
241 | extraFlagField.invoke(window, true ? darkModeFlag : 0, darkModeFlag);
242 | } catch (Exception e) {
243 | e.printStackTrace();
244 | }
245 | WindowManager.LayoutParams winParams = window.getAttributes();
246 | int bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;
247 | winParams.flags |= bits;
248 | window.setAttributes(winParams);
249 | return true;
250 | } else if (osType == OSInfo.OSType.OS_TYPE_FLYME) {
251 | FlymeStatusbarColorUtils.setStatusBarDarkIcon(activity, true);
252 | WindowManager.LayoutParams winParams = window.getAttributes();
253 | int bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;
254 | winParams.flags |= bits;
255 | window.setAttributes(winParams);
256 | return true;
257 | }
258 | }
259 | return false;
260 | }
261 |
262 | /**
263 | * 设置状态栏字符颜色是否变为深
264 | * 支持6.0以上的普通机型
265 | * 支持5.1以上的oppo机型
266 | * 支持所有小米机型
267 | * 支持所有魅族机型
268 | * @param activity
269 | * @param isLight
270 | */
271 | public static void setStatusBarLightStatus(Activity activity, boolean isLight) {
272 | if (isLight) {
273 | OSInfo.OSType osType = OSInfo.getRomType(activity);
274 | Window window = activity.getWindow();
275 | View decorView = window.getDecorView();
276 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
277 | window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
278 | int systemUiVisibility = window.getDecorView().getSystemUiVisibility();
279 | systemUiVisibility |= View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
280 | decorView.setSystemUiVisibility(systemUiVisibility);
281 | } else if (osType == OSInfo.OSType.OS_TYPE_MIUI) {
282 | Class extends Window> clazz = window.getClass();
283 | try {
284 | int darkModeFlag = 0;
285 | Class> layoutParams = Class.forName("android.view.MiuiWindowManager$LayoutParams");
286 | Field field = layoutParams.getField("EXTRA_FLAG_STATUS_BAR_DARK_MODE");
287 | darkModeFlag = field.getInt(layoutParams);
288 | Method extraFlagField = clazz.getMethod("setExtraFlags", int.class, int.class);
289 | extraFlagField.invoke(window, true ? darkModeFlag : 0, darkModeFlag);
290 | } catch (Exception e) {
291 | e.printStackTrace();
292 | }
293 | } else if (osType == OSInfo.OSType.OS_TYPE_FLYME) {
294 | FlymeStatusbarColorUtils.setStatusBarDarkIcon(activity, true);
295 | } else if (osType == OSInfo.OSType.OS_TYPE_COLOR && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
296 | window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
297 | int systemUiVisibility = window.getDecorView().getSystemUiVisibility();
298 | systemUiVisibility |= SYSTEM_UI_FLAG_OP_STATUS_BAR_TINT;
299 | decorView.setSystemUiVisibility(systemUiVisibility);
300 | }
301 | } else {
302 | OSInfo.OSType osType = OSInfo.getRomType(activity);
303 | Window window = activity.getWindow();
304 | View decorView = window.getDecorView();
305 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
306 | window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
307 | int systemUiVisibility = window.getDecorView().getSystemUiVisibility();
308 | systemUiVisibility &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
309 | decorView.setSystemUiVisibility(systemUiVisibility);
310 | } else if (osType == OSInfo.OSType.OS_TYPE_MIUI) {
311 | Class extends Window> clazz = window.getClass();
312 | try {
313 | int darkModeFlag = 0;
314 | Class> layoutParams = Class.forName("android.view.MiuiWindowManager$LayoutParams");
315 | Field field = layoutParams.getField("EXTRA_FLAG_STATUS_BAR_DARK_MODE");
316 | darkModeFlag = field.getInt(layoutParams);
317 | Method extraFlagField = clazz.getMethod("setExtraFlags", int.class, int.class);
318 | extraFlagField.invoke(window, false ? darkModeFlag : 0, darkModeFlag);
319 | } catch (Exception e) {
320 | e.printStackTrace();
321 | }
322 | } else if (osType == OSInfo.OSType.OS_TYPE_FLYME) {
323 | FlymeStatusbarColorUtils.setStatusBarDarkIcon(activity, false);
324 | } else if (osType == OSInfo.OSType.OS_TYPE_COLOR && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
325 | window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
326 | int systemUiVisibility = window.getDecorView().getSystemUiVisibility();
327 | systemUiVisibility &= ~SYSTEM_UI_FLAG_OP_STATUS_BAR_TINT;
328 | decorView.setSystemUiVisibility(systemUiVisibility);
329 | }
330 | }
331 | }
332 |
333 | /**
334 | * 获取状态栏颜色
335 | * 5.0以上所有机型可以正常获取,5.0以下机型统一返回黑色
336 | * @param activity
337 | * @return
338 | */
339 | public static int getStatusBarColor(Activity activity) {
340 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
341 | int color = activity.getWindow().getStatusBarColor();
342 | return color;
343 | } else {
344 | return Color.BLACK;
345 | }
346 | }
347 |
348 | /**
349 | * 获取状态栏高度
350 | * @param context
351 | * @return
352 | */
353 | public static int getStatusBarHeight(Context context) {
354 | int resourceId = context.getResources().getIdentifier("status_bar_height", "dimen", "android");
355 | if (resourceId > 0) {
356 | return context.getResources().getDimensionPixelSize(resourceId);
357 | } else {
358 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
359 | return (int) (TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 24.0f, context.getResources().getDisplayMetrics()) + 0.5f);
360 | } else {
361 | return (int) (TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 25.0f, context.getResources().getDisplayMetrics()) + 0.5f);
362 | }
363 | }
364 | }
365 | }
366 |
--------------------------------------------------------------------------------
/statusbarutils/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | statusbarutils
3 |
4 |
--------------------------------------------------------------------------------
/statusbarutils/src/test/java/com/github/xubo/statusbarutils/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.github.xubo.statusbarutils;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | * @see Testing documentation
10 | */
11 | public class ExampleUnitTest {
12 | @Test
13 | public void addition_isCorrect() {
14 | assertEquals(4, 2 + 2);
15 | }
16 | }
--------------------------------------------------------------------------------
/statusbarutils/version.gradle:
--------------------------------------------------------------------------------
1 | ext {
2 | //版本code
3 | versionCode = 2
4 | //版本名
5 | versionName = "1.0.1"
6 | }
--------------------------------------------------------------------------------