├── app
├── .gitignore
├── release
│ ├── app-release.apk
│ └── output.json
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── values
│ │ │ │ ├── strings.xml
│ │ │ │ ├── colors.xml
│ │ │ │ └── styles.xml
│ │ │ ├── drawable
│ │ │ │ ├── happynewyear.jpg
│ │ │ │ └── full_screen_text.jpg
│ │ │ ├── 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
│ │ │ ├── layout
│ │ │ │ ├── activity_fullscreen_no_text.xml
│ │ │ │ ├── fragment_no_have_tool.xml
│ │ │ │ ├── activity_toolbar_andstatusbar_same_color.xml
│ │ │ │ ├── fragment_have_havetool.xml
│ │ │ │ ├── activity_fullscreen_text.xml
│ │ │ │ ├── activity_in_fragment_status.xml
│ │ │ │ └── activity_main.xml
│ │ │ └── values-v21
│ │ │ │ └── styles.xml
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── example
│ │ │ │ └── foking
│ │ │ │ └── myapplication
│ │ │ │ ├── ChangeStatusBarColorActivity.java
│ │ │ │ ├── FullScrrenNoTextActivity.java
│ │ │ │ ├── FullScrrenHaveTextActivity.java
│ │ │ │ ├── FragmentUtil.java
│ │ │ │ ├── MainActivity.java
│ │ │ │ ├── ToolBarAndStatusBarSameColorActivity.java
│ │ │ │ ├── BaseNoStatusBarFragment.java
│ │ │ │ └── FragmentStatusAndActionBarActivity.java
│ │ └── AndroidManifest.xml
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── example
│ │ │ └── foking
│ │ │ └── myapplication
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── example
│ │ └── foking
│ │ └── myapplication
│ │ └── ExampleInstrumentedTest.java
├── proguard-rules.pro
└── build.gradle
├── settings.gradle
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .gitignore
├── gradle.properties
├── gradlew.bat
└── gradlew
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------
/app/release/app-release.apk:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FokingGit/StatusBarDemo/HEAD/app/release/app-release.apk
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | My Application
3 |
4 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FokingGit/StatusBarDemo/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/app/src/main/res/drawable/happynewyear.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FokingGit/StatusBarDemo/HEAD/app/src/main/res/drawable/happynewyear.jpg
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FokingGit/StatusBarDemo/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FokingGit/StatusBarDemo/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/full_screen_text.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FokingGit/StatusBarDemo/HEAD/app/src/main/res/drawable/full_screen_text.jpg
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FokingGit/StatusBarDemo/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FokingGit/StatusBarDemo/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FokingGit/StatusBarDemo/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FokingGit/StatusBarDemo/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FokingGit/StatusBarDemo/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FokingGit/StatusBarDemo/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FokingGit/StatusBarDemo/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FokingGit/StatusBarDemo/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/release/output.json:
--------------------------------------------------------------------------------
1 | [{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":1},"path":"app-release.apk","properties":{"packageId":"com.example.foking.myapplication","split":"","minSdkVersion":"15"}}]
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/libraries
5 | /.idea/modules.xml
6 | /.idea/workspace.xml
7 | .DS_Store
8 | /build
9 | /captures
10 | .externalNativeBuild
11 | /app/build
12 | .idea
13 |
14 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Sat Jan 06 19:31:58 CST 2018
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 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 | #ff0000
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_fullscreen_no_text.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values-v21/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_no_have_tool.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
11 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_toolbar_andstatusbar_same_color.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
10 |
11 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_have_havetool.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_fullscreen_text.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
12 |
13 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx1536m
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/foking/myapplication/ChangeStatusBarColorActivity.java:
--------------------------------------------------------------------------------
1 | package com.example.foking.myapplication;
2 |
3 | import android.os.Build;
4 | import android.os.Bundle;
5 | import android.support.annotation.Nullable;
6 | import android.support.v7.app.AppCompatActivity;
7 | import android.view.View;
8 |
9 |
10 | public class ChangeStatusBarColorActivity extends AppCompatActivity {
11 | @Override
12 | protected void onCreate(@Nullable Bundle savedInstanceState) {
13 | super.onCreate(savedInstanceState);
14 | setContentView(R.layout.activity_fullscreen_no_text);
15 | //设置白底黑字
16 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
17 | getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
18 | }
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/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/main/java/com/example/foking/myapplication/FullScrrenNoTextActivity.java:
--------------------------------------------------------------------------------
1 | package com.example.foking.myapplication;
2 |
3 | import android.os.Bundle;
4 | import android.support.annotation.Nullable;
5 | import android.support.v7.app.AppCompatActivity;
6 | import android.view.View;
7 | import android.view.WindowManager;
8 |
9 |
10 | public class FullScrrenNoTextActivity extends AppCompatActivity {
11 | @Override
12 | protected void onCreate(@Nullable Bundle savedInstanceState) {
13 | super.onCreate(savedInstanceState);
14 | setContentView(R.layout.activity_fullscreen_no_text);
15 | //方式一
16 | //getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
17 | //方式二
18 | //getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN);
19 | //方式三 style.xml中配置
20 | //
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 25
5 | defaultConfig {
6 | applicationId "com.example.foking.myapplication"
7 | minSdkVersion 15
8 | targetSdkVersion 24
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(include: ['*.jar'], dir: 'libs')
23 | implementation 'com.android.support:appcompat-v7:25.3.0'
24 | implementation 'com.android.support.constraint:constraint-layout:1.0.2'
25 | testImplementation 'junit:junit:4.12'
26 | androidTestImplementation 'com.android.support.test:runner:1.0.1'
27 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
28 | compile 'com.jakewharton:butterknife:8.6.0'
29 | annotationProcessor 'com.jakewharton:butterknife-compiler:8.6.0'
30 | }
31 |
--------------------------------------------------------------------------------
/app/src/test/java/com/example/foking/myapplication/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.example.foking.myapplication;
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 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 |
18 | @Test
19 | public void testArray() {
20 | int x = 2;
21 | int i = (x++) / 3;
22 | //先进行其他运算,再进行自增或者自减
23 | System.out.println(i);
24 | }
25 |
26 | @Test
27 | public void testSwitch() {
28 | int x = 4;
29 | int j = 0;
30 | switch (x) {
31 | case 1:
32 | j++;
33 | case 2:
34 | j++;
35 | case 3:
36 | j++;
37 | case 4:
38 | System.out.println("case 4");
39 | j++;
40 | case 5:
41 | System.out.println("case 5");
42 | j++;
43 | default:
44 | j++;
45 | }
46 |
47 | System.out.println(j);
48 | }
49 |
50 | }
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
14 |
15 |
17 |
23 |
24 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/example/foking/myapplication/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.example.foking.myapplication;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 | import android.util.Log;
7 | import android.view.ViewGroup;
8 |
9 | import org.junit.Test;
10 | import org.junit.runner.RunWith;
11 |
12 | import static org.junit.Assert.*;
13 |
14 | /**
15 | * Instrumented test, which will execute on an Android device.
16 | *
17 | * @see Testing documentation
18 | */
19 | @RunWith(AndroidJUnit4.class)
20 | public class ExampleInstrumentedTest {
21 | @Test
22 | public void useAppContext() throws Exception {
23 | // Context of the app under test.
24 | Context appContext = InstrumentationRegistry.getTargetContext();
25 | }
26 |
27 | private void printChildView(ViewGroup viewGroup) {
28 | Log.i("printView-ViewGroup", viewGroup.getClass().getSimpleName() + "的子View和数量:" + viewGroup.getChildCount());
29 | for (int i = 0; i < viewGroup.getChildCount(); i++) {
30 | if (viewGroup.getChildAt(i) instanceof ViewGroup) {
31 | printChildView((ViewGroup) viewGroup.getChildAt(i));
32 | } else {
33 | Log.i("printView", viewGroup.getChildAt(i).getClass().getSimpleName() + "是" + viewGroup.getClass().getSimpleName() + "的子View");
34 | }
35 | }
36 | }
37 |
38 | private void testRxJava() {
39 |
40 | }
41 |
42 |
43 | }
44 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/foking/myapplication/FullScrrenHaveTextActivity.java:
--------------------------------------------------------------------------------
1 | package com.example.foking.myapplication;
2 |
3 | import android.os.Build;
4 | import android.os.Bundle;
5 | import android.support.annotation.Nullable;
6 | import android.support.v7.app.AppCompatActivity;
7 | import android.view.View;
8 | import android.view.ViewGroup;
9 | import android.view.Window;
10 | import android.view.WindowManager;
11 |
12 |
13 | public class FullScrrenHaveTextActivity extends AppCompatActivity {
14 | @Override
15 | protected void onCreate(@Nullable Bundle savedInstanceState) {
16 | super.onCreate(savedInstanceState);
17 | setContentView(R.layout.activity_fullscreen_text);
18 | Window window = getWindow();
19 | if (Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN_MR2) {
20 | window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
21 | ViewGroup contentView = (ViewGroup) window.getDecorView().findViewById(Window.ID_ANDROID_CONTENT);
22 | contentView.getChildAt(0).setFitsSystemWindows(false);
23 | }
24 | /*
25 | 这里fitsSystemWindows是什么意思呢?相信很多人会有疑问?
26 | 注意不是设置 ContentView 的 FitsSystemWindows, 而是设置 ContentView 的第一个子 View . 预留出系统 View 的空间.
27 | 看我们代码流程,首先是设置了FLAG_TRANSLUCENT_STATUS 将状态栏设置为透明的状态
28 | fitsSystemWindows代表的是:当设置SystemBar(包含StatusBar&NavigationBar)透明之后,
29 | 将fitsSystemWindows至为true,则还是为SystemBar预留空间,当设置为false的时候,就是不为SystemBar预留空间
30 | 现在这个业务场景是不为StatusBar预留空间,所以我们先将StatusBar设置为透明,然后不预留空间
31 | 这样就实现了我们的功能,全屏但是不隐藏statusBar文字
32 | */
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
23 |
27 |
31 |
35 |
39 |
40 |
41 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/foking/myapplication/FragmentUtil.java:
--------------------------------------------------------------------------------
1 | package com.example.foking.myapplication;
2 |
3 | import android.content.ContextWrapper;
4 | import android.support.v4.app.Fragment;
5 | import android.support.v4.app.FragmentActivity;
6 | import android.support.v4.app.FragmentTransaction;
7 | import android.support.v7.app.AppCompatActivity;
8 |
9 | public class FragmentUtil {
10 |
11 | /**
12 | * 判断当前Fragment的getActivity是否可用
13 | *
14 | * @param fragment
15 | * @return
16 | */
17 | public static boolean judgeGetActivityCanUse(Fragment fragment) {
18 | if (null != fragment) {
19 | FragmentActivity activity = fragment.getActivity();
20 | if (null != activity
21 | && !activity.isFinishing()
22 | && !fragment.isDetached()
23 | && activity instanceof ContextWrapper) {
24 | return true;
25 | } else {
26 | return false;
27 | }
28 | } else {
29 | return false;
30 | }
31 | }
32 |
33 | public static void replaceSupportFragment(AppCompatActivity activity, int containerId, Class extends Fragment> fragmentClass, String tag, boolean addToBackStack) {
34 | try {
35 | FragmentTransaction transaction = activity.getSupportFragmentManager().beginTransaction();
36 | if (addToBackStack) {
37 | transaction.addToBackStack(null);
38 | }
39 | transaction.replace(containerId, fragmentClass.newInstance(), tag);
40 | transaction.commitAllowingStateLoss();
41 | } catch (InstantiationException e) {
42 | e.printStackTrace();
43 | } catch (IllegalAccessException e) {
44 | e.printStackTrace();
45 | }
46 | }
47 |
48 | }
49 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/foking/myapplication/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.example.foking.myapplication;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import android.support.v7.app.AppCompatActivity;
6 | import android.view.View;
7 | import android.widget.Button;
8 |
9 | import butterknife.BindView;
10 | import butterknife.ButterKnife;
11 | import butterknife.OnClick;
12 |
13 | public class MainActivity extends AppCompatActivity {
14 |
15 |
16 | @BindView(R.id.bt_fullscreen_notext)
17 | Button btFullscreenNotext;
18 | @BindView(R.id.bt_fullscreen_text)
19 | Button btFullscreenText;
20 | @BindView(R.id.bt_toolbar_status_same_color)
21 | Button btToolbarStatusSameColor;
22 | @BindView(R.id.bt_change_statusbar_text_colr)
23 | Button btChangeStatusbarTextColr;
24 | @BindView(R.id.bt_fragment_status)
25 | Button btFragmentStatus;
26 |
27 | @Override
28 | protected void onCreate(Bundle savedInstanceState) {
29 | super.onCreate(savedInstanceState);
30 | setContentView(R.layout.activity_main);
31 | ButterKnife.bind(this);
32 | }
33 |
34 | @OnClick({R.id.bt_fullscreen_notext, R.id.bt_fullscreen_text, R.id.bt_fragment_status, R.id.bt_toolbar_status_same_color, R.id.bt_change_statusbar_text_colr})
35 | public void onViewClicked(View view) {
36 | Intent intent = new Intent();
37 | Class clazz = null;
38 | switch (view.getId()) {
39 | case R.id.bt_fullscreen_notext:
40 | clazz = FullScrrenNoTextActivity.class;
41 | break;
42 | case R.id.bt_fullscreen_text:
43 | clazz = FullScrrenHaveTextActivity.class;
44 | break;
45 | case R.id.bt_toolbar_status_same_color:
46 | clazz = ToolBarAndStatusBarSameColorActivity.class;
47 | break;
48 | case R.id.bt_change_statusbar_text_colr:
49 | clazz = ChangeStatusBarColorActivity.class;
50 | break;
51 | case R.id.bt_fragment_status:
52 | clazz = FragmentStatusAndActionBarActivity.class;
53 | break;
54 | }
55 | intent.setClass(MainActivity.this, clazz);
56 | startActivity(intent);
57 | }
58 |
59 | }
60 |
--------------------------------------------------------------------------------
/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 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
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 Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_in_fragment_status.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
15 |
16 |
22 |
23 |
24 |
29 |
30 |
31 |
32 |
36 |
37 |
40 |
46 |
47 |
53 |
54 |
55 |
58 |
64 |
70 |
71 |
72 |
73 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/foking/myapplication/ToolBarAndStatusBarSameColorActivity.java:
--------------------------------------------------------------------------------
1 | package com.example.foking.myapplication;
2 |
3 | import android.os.Build;
4 | import android.os.Bundle;
5 | import android.support.annotation.Nullable;
6 | import android.support.v4.view.ViewCompat;
7 | import android.support.v7.app.AppCompatActivity;
8 | import android.util.Log;
9 | import android.view.View;
10 | import android.view.ViewGroup;
11 | import android.view.Window;
12 | import android.view.WindowManager;
13 |
14 |
15 | public class ToolBarAndStatusBarSameColorActivity extends AppCompatActivity {
16 | @Override
17 | protected void onCreate(@Nullable Bundle savedInstanceState) {
18 | super.onCreate(savedInstanceState);
19 | setContentView(R.layout.activity_toolbar_andstatusbar_same_color);
20 |
21 | Window window = getWindow();
22 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
23 | window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
24 | window.setStatusBarColor(getResources().getColor(R.color.status_toolBar_same_color));
25 | } else {
26 | window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
27 | ViewGroup systemContent = (ViewGroup) findViewById(android.R.id.content);
28 |
29 | View statusBarView = new View(this);
30 | ViewGroup.LayoutParams lp = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, getStatusBarHeight());
31 | statusBarView.setBackgroundColor(getResources().getColor(R.color.status_toolBar_same_color));
32 |
33 | systemContent.getChildAt(0).setFitsSystemWindows(false);
34 |
35 | systemContent.addView(statusBarView, 0, lp);
36 |
37 | }
38 | printChildView((ViewGroup) window.getDecorView());
39 |
40 | }
41 |
42 | public int getStatusBarHeight() {
43 | int statusBarHeight1 = -1;
44 | //获取status_bar_height资源的ID
45 | int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
46 | if (resourceId > 0) {
47 | //根据资源ID获取响应的尺寸值
48 | statusBarHeight1 = getResources().getDimensionPixelSize(resourceId);
49 | }
50 | return statusBarHeight1;
51 | }
52 |
53 | private void printChildView(ViewGroup viewGroup) {
54 | Log.i("printView-ViewGroup", viewGroup.getClass().getSimpleName() + "的子View和数量:" + viewGroup.getChildCount());
55 | for (int i = 0; i < viewGroup.getChildCount(); i++) {
56 | String simpleName = viewGroup.getChildAt(i).getClass().getSimpleName();
57 | Log.i("printView-ChildView", simpleName);
58 | }
59 | for (int i = 0; i < viewGroup.getChildCount(); i++) {
60 | if (viewGroup.getChildAt(i) instanceof ViewGroup) {
61 | printChildView((ViewGroup) viewGroup.getChildAt(i));
62 | }
63 | }
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
20 |
21 |
32 |
33 |
44 |
45 |
56 |
57 |
68 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/foking/myapplication/BaseNoStatusBarFragment.java:
--------------------------------------------------------------------------------
1 | package com.example.foking.myapplication;
2 |
3 | import android.content.Context;
4 | import android.nfc.Tag;
5 | import android.os.Bundle;
6 | import android.support.annotation.Nullable;
7 | import android.support.v4.app.Fragment;
8 | import android.util.Log;
9 | import android.view.LayoutInflater;
10 | import android.view.View;
11 | import android.view.ViewGroup;
12 |
13 | import butterknife.ButterKnife;
14 |
15 |
16 | /**
17 | * Created by fengjian on 2017/10/19.
18 | * function:
19 | */
20 |
21 | public abstract class BaseNoStatusBarFragment extends Fragment {
22 |
23 | public static String TAG = "BaseNoStatusBarFragment";
24 | private ViewGroup mView;
25 |
26 |
27 | @Override
28 | public void onHiddenChanged(boolean hidden) {
29 | Log.i(TAG, getClass().getSimpleName() + ":onHiddenChanged");
30 | if (!hidden && FragmentUtil.judgeGetActivityCanUse(this)) {
31 | getActivity().setTitle(getFragmentTitle());
32 | }
33 | }
34 |
35 | protected abstract void configFragmentView(View view);
36 |
37 | public abstract int getFragmentView();
38 |
39 | public abstract String getFragmentTitle();
40 |
41 | @Override
42 | public void onAttach(Context context) {
43 | super.onAttach(context);
44 | Log.i(TAG, getClass().getSimpleName() + ":onAttach");
45 | }
46 |
47 | @Override
48 | public void onCreate(@Nullable Bundle savedInstanceState) {
49 | super.onCreate(savedInstanceState);
50 | Log.i(TAG, getClass().getSimpleName() + ":onCreate");
51 | }
52 |
53 | @Nullable
54 | @Override
55 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
56 | Log.i(TAG, getClass().getSimpleName() + ":onCreateView");
57 | mView = (ViewGroup) LayoutInflater.from(getActivity()).inflate(getFragmentView(), container, false);
58 | return mView;
59 | }
60 |
61 | @Override
62 | public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
63 | Log.i(TAG, getClass().getSimpleName() + ":onViewCreated");
64 | ButterKnife.bind(view);
65 | configFragmentView(view);
66 | }
67 |
68 | @Override
69 | public void onActivityCreated(@Nullable Bundle savedInstanceState) {
70 | Log.i(TAG, getClass().getSimpleName() + ":onActivityCreated");
71 | getActivity().setTitle(getFragmentTitle());
72 | super.onActivityCreated(savedInstanceState);
73 | }
74 |
75 | @Override
76 | public void onStart() {
77 | Log.i(TAG, getClass().getSimpleName() + ":onStart");
78 | super.onStart();
79 | }
80 |
81 | @Override
82 | public void onResume() {
83 | Log.i(TAG, getClass().getSimpleName() + ":onResume");
84 | super.onResume();
85 | }
86 |
87 | @Override
88 | public void onPause() {
89 | Log.i(TAG, getClass().getSimpleName() + ":onPause");
90 | super.onPause();
91 | }
92 |
93 | @Override
94 | public void onStop() {
95 | Log.i(TAG, getClass().getSimpleName() + ":onStop");
96 | super.onStop();
97 | }
98 |
99 | @Override
100 | public void onDestroyView() {
101 | Log.i(TAG, getClass().getSimpleName() + ":onDestroyView");
102 | super.onDestroyView();
103 | }
104 |
105 |
106 | @Override
107 | public void onDestroy() {
108 | Log.i(TAG, getClass().getSimpleName() + ":onDestroy");
109 | super.onDestroy();
110 | }
111 |
112 | @Override
113 | public void onDetach() {
114 | Log.i(TAG, getClass().getSimpleName() + ":onDetach");
115 | super.onDetach();
116 | }
117 |
118 |
119 | }
120 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/foking/myapplication/FragmentStatusAndActionBarActivity.java:
--------------------------------------------------------------------------------
1 | package com.example.foking.myapplication;
2 |
3 | import android.content.Context;
4 | import android.graphics.Color;
5 | import android.os.Build;
6 | import android.os.Bundle;
7 | import android.support.annotation.IdRes;
8 | import android.support.annotation.Nullable;
9 | import android.support.v4.app.Fragment;
10 | import android.support.v4.app.FragmentManager;
11 | import android.support.v4.app.FragmentTransaction;
12 | import android.support.v7.app.AppCompatActivity;
13 | import android.support.v7.widget.Toolbar;
14 | import android.util.Log;
15 | import android.view.LayoutInflater;
16 | import android.view.View;
17 | import android.view.ViewGroup;
18 | import android.view.Window;
19 | import android.view.WindowManager;
20 | import android.widget.TextView;
21 |
22 | import java.util.ArrayList;
23 |
24 |
25 | public class FragmentStatusAndActionBarActivity extends AppCompatActivity {
26 | public Toolbar mToolbar;
27 | public TextView mTitle;
28 | private ArrayList mFragments;
29 | private FragmentManager mSupportFragmentManager;
30 | private FragmentTransaction mFragmentTransaction;
31 | private Fragment mLastFragment;
32 | protected View mStatusBarView;
33 |
34 | @Override
35 | protected void onCreate(@Nullable Bundle savedInstanceState) {
36 | super.onCreate(savedInstanceState);
37 | setContentView(R.layout.activity_in_fragment_status);
38 |
39 | mToolbar = (Toolbar) findViewById(R.id.base_toolbar);
40 | mTitle = (TextView) findViewById(R.id.base_title);
41 |
42 |
43 | setSupportActionBar(mToolbar);
44 | getSupportActionBar().setDisplayHomeAsUpEnabled(false);
45 | getSupportActionBar().setDisplayShowTitleEnabled(false);
46 |
47 | mFragments = new ArrayList<>();
48 | HaveToolBarFragment haveToolBarFragment = new HaveToolBarFragment();
49 | NoToolBarStatusFragment noToolBarStatusFragment = new NoToolBarStatusFragment();
50 | ToolBarStatusDifColorFragment toolBarStatusDifColorFragment = new ToolBarStatusDifColorFragment();
51 | OnlyBannerFragment onlyBannerFragment = new OnlyBannerFragment();
52 |
53 |
54 | mFragments.add(haveToolBarFragment);
55 | mFragments.add(noToolBarStatusFragment);
56 | mFragments.add(toolBarStatusDifColorFragment);
57 | mFragments.add(onlyBannerFragment);
58 |
59 | mSupportFragmentManager = getSupportFragmentManager();
60 |
61 |
62 | findViewById(R.id.bt_have_tool_bar).setOnClickListener(new View.OnClickListener() {
63 | @Override
64 | public void onClick(View view) {
65 | selectFragment(0);
66 | }
67 | });
68 |
69 | findViewById(R.id.bt_no_have_toolbar).setOnClickListener(new View.OnClickListener() {
70 | @Override
71 | public void onClick(View view) {
72 | selectFragment(1);
73 | }
74 | });
75 |
76 | findViewById(R.id.bt_have_toolbar_change_color).setOnClickListener(new View.OnClickListener() {
77 | @Override
78 | public void onClick(View v) {
79 | selectFragment(2);
80 | }
81 | });
82 |
83 | findViewById(R.id.bt_only_banner).setOnClickListener(new View.OnClickListener() {
84 | @Override
85 | public void onClick(View v) {
86 | selectFragment(3);
87 | }
88 | });
89 |
90 |
91 | addStatusBar();
92 | selectFragment(0);
93 | }
94 |
95 | private void addStatusBar() {
96 | //条件状态栏透明,要不然不会起作用
97 | getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
98 | if (mStatusBarView == null) {
99 | mStatusBarView = new View(FragmentStatusAndActionBarActivity.this);
100 | int screenWidth = getResources().getDisplayMetrics().widthPixels;
101 | int statusBarHeight = getStatusBarHeight();
102 | ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(screenWidth, statusBarHeight);
103 | mStatusBarView.setLayoutParams(params);
104 | mStatusBarView.requestLayout();
105 |
106 | //获取根布局
107 | ViewGroup systemContent = (ViewGroup) findViewById(android.R.id.content);
108 | ViewGroup userContent = (ViewGroup) systemContent.getChildAt(0);
109 | userContent.setFitsSystemWindows(false);
110 | userContent.addView(mStatusBarView, 0);
111 | }
112 | }
113 |
114 | public int getStatusBarHeight() {
115 | int statusBarHeight1 = -1;
116 | //获取status_bar_height资源的ID
117 | int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
118 | if (resourceId > 0) {
119 | //根据资源ID获取响应的尺寸值
120 | statusBarHeight1 = getResources().getDimensionPixelSize(resourceId);
121 | }
122 | return statusBarHeight1;
123 | }
124 |
125 | @Override
126 | public void setTitle(CharSequence title) {
127 | mTitle.setText(title);
128 | }
129 |
130 | private void selectFragment(int index) {
131 | if (mFragments != null && mFragments.size() > 0) {
132 | mFragmentTransaction = mSupportFragmentManager.beginTransaction();
133 | Fragment baseFragment = mFragments.get(index);
134 | if (mLastFragment != null) {
135 | mFragmentTransaction.hide(mLastFragment);
136 | }
137 | if (mFragmentTransaction != null) {
138 | if (baseFragment.isAdded()) {
139 | mFragmentTransaction.show(baseFragment);
140 | } else {
141 | mFragmentTransaction.add(R.id.base_container, baseFragment);
142 | }
143 | }
144 | mFragmentTransaction.commitAllowingStateLoss();
145 | mLastFragment = baseFragment;
146 | }
147 | }
148 |
149 | public static class HaveToolBarFragment extends BaseNoStatusBarFragment {
150 |
151 | private FragmentStatusAndActionBarActivity mActivity;
152 |
153 | @Override
154 | protected void configFragmentView(View view) {
155 | mActivity = ((FragmentStatusAndActionBarActivity) getActivity());
156 | mActivity.mToolbar.setVisibility(View.VISIBLE);
157 | mActivity.mToolbar.setBackgroundColor(getResources().getColor(R.color.colorPrimaryDark));
158 | mActivity.mStatusBarView.setBackgroundColor(getResources().getColor(android.R.color.holo_blue_bright));
159 | mActivity.mStatusBarView.setVisibility(View.VISIBLE);
160 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
161 | mActivity.getWindow().getDecorView().setSystemUiVisibility(View.VISIBLE);
162 | }
163 |
164 | @Override
165 | public void onHiddenChanged(boolean hidden) {
166 | super.onHiddenChanged(hidden);
167 | mActivity.mToolbar.setVisibility(View.VISIBLE);//设置ToolBar显示
168 | mActivity.mToolbar.setBackgroundColor(getResources().getColor(R.color.colorPrimaryDark));
169 | mActivity.mStatusBarView.setBackgroundColor(getResources().getColor(android.R.color.holo_blue_bright));
170 | mActivity.mStatusBarView.setVisibility(View.VISIBLE);
171 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
172 | mActivity.getWindow().getDecorView().setSystemUiVisibility(View.VISIBLE);
173 | }
174 |
175 | @Override
176 | public int getFragmentView() {
177 | return R.layout.fragment_have_havetool;
178 | }
179 |
180 | @Override
181 | public String getFragmentTitle() {
182 | return "yes";
183 | }
184 | }
185 |
186 | public static class NoToolBarStatusFragment extends BaseNoStatusBarFragment {
187 | private FragmentStatusAndActionBarActivity mActivity;
188 |
189 |
190 | @Override
191 | protected void configFragmentView(View view) {
192 | mActivity = ((FragmentStatusAndActionBarActivity) getActivity());
193 | mActivity.mToolbar.setVisibility(View.GONE);
194 | mActivity.mToolbar.setBackgroundColor(getResources().getColor(R.color.colorPrimaryDark));
195 | mActivity.mStatusBarView.setBackgroundColor(getResources().getColor(android.R.color.holo_orange_light));
196 | mActivity.mStatusBarView.setVisibility(View.VISIBLE);
197 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
198 | mActivity.getWindow().getDecorView().setSystemUiVisibility(View.VISIBLE);
199 | }
200 |
201 | @Override
202 | public void onHiddenChanged(boolean hidden) {
203 | super.onHiddenChanged(hidden);
204 | mActivity.mToolbar.setVisibility(View.GONE);//设置ToolBar消失
205 | mActivity.mToolbar.setBackgroundColor(getResources().getColor(R.color.colorPrimaryDark));
206 | mActivity.mStatusBarView.setBackgroundColor(getResources().getColor(android.R.color.holo_orange_light));
207 | mActivity.mStatusBarView.setVisibility(View.VISIBLE);
208 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
209 | mActivity.getWindow().getDecorView().setSystemUiVisibility(View.VISIBLE);
210 | }
211 |
212 | @Override
213 | public int getFragmentView() {
214 | return R.layout.fragment_no_have_tool;
215 | }
216 |
217 | @Override
218 | public String getFragmentTitle() {
219 | return "no";
220 | }
221 |
222 |
223 | }
224 |
225 | public static class ToolBarStatusDifColorFragment extends BaseNoStatusBarFragment {
226 | private FragmentStatusAndActionBarActivity mActivity;
227 |
228 |
229 | @Override
230 | protected void configFragmentView(View view) {
231 | mActivity = ((FragmentStatusAndActionBarActivity) getActivity());
232 | mActivity.mToolbar.setVisibility(View.VISIBLE);
233 | mActivity.mToolbar.setBackgroundColor(getResources().getColor(R.color.colorAccent));
234 | mActivity.mStatusBarView.setVisibility(View.VISIBLE);
235 | mActivity.mStatusBarView.setBackgroundColor(getResources().getColor(R.color.colorAccent));
236 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
237 | mActivity.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
238 | }
239 |
240 | @Override
241 | public void onHiddenChanged(boolean hidden) {
242 | super.onHiddenChanged(hidden);
243 | mActivity.mToolbar.setVisibility(View.VISIBLE);
244 | mActivity.mToolbar.setBackgroundColor(getResources().getColor(R.color.colorAccent));
245 | mActivity.mStatusBarView.setBackgroundColor(getResources().getColor(R.color.colorAccent));
246 | mActivity.mStatusBarView.setVisibility(View.VISIBLE);
247 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
248 | mActivity.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
249 | }
250 |
251 | @Override
252 | public int getFragmentView() {
253 | return R.layout.fragment_no_have_tool;
254 | }
255 |
256 | @Override
257 | public String getFragmentTitle() {
258 | return "no";
259 | }
260 |
261 |
262 | }
263 |
264 | public static class OnlyBannerFragment extends BaseNoStatusBarFragment {
265 | private FragmentStatusAndActionBarActivity mActivity;
266 |
267 |
268 | @Override
269 | protected void configFragmentView(View view) {
270 | mActivity = ((FragmentStatusAndActionBarActivity) getActivity());
271 | mActivity.mToolbar.setVisibility(View.GONE);
272 | mActivity.mStatusBarView.setVisibility(View.GONE);
273 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
274 | mActivity.getWindow().getDecorView().setSystemUiVisibility(View.VISIBLE);
275 | }
276 |
277 | @Override
278 | public void onHiddenChanged(boolean hidden) {
279 | super.onHiddenChanged(hidden);
280 | mActivity.mToolbar.setVisibility(View.GONE);
281 | mActivity.mStatusBarView.setVisibility(View.GONE);
282 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
283 | mActivity.getWindow().getDecorView().setSystemUiVisibility(View.VISIBLE);
284 | mActivity.mStatusBarView.setVisibility(View.GONE);
285 | }
286 |
287 | @Override
288 | public int getFragmentView() {
289 | return R.layout.fragment_no_have_tool;
290 | }
291 |
292 | @Override
293 | public String getFragmentTitle() {
294 | return "no";
295 | }
296 | }
297 | }
298 |
299 |
--------------------------------------------------------------------------------