├── .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 |