Android phone status bar

1, Full screen without status bar (welcome page):

Set in style.xml


    <style name="Theme.AppStartLoadTranslucent" parent="AppTheme">
        <item name="android:windowIsTranslucent">true</item>
        <item name="android:windowFullscreen">true</item>
    </style>

Set in Activity:

public class WelcomeActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_welcome);
//Full screen display
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        Timer timer = new Timer();// Instantiate Timer class
        timer.schedule(new TimerTask() {
            public void run() {
                Intent intent = new Intent(WelcomeActivity.this,
                        MainActivity.class);
                startActivity(intent);
                finish();
            }
        }, 3000);// Five hundred milliseconds
    }

}

To remove the white flash screen from the welcome page:

To solve this problem, you only need to set a transparent Theme, and add the following code in styles.xml

<style name="WelcomeTheme" parent="AppTheme">
        <item name="android:windowIsTranslucent">true</item>
    </style>

Set in minifest.xml:


        <activity
            android:name=".view.login.WelcomeActivity"
            android:alwaysRetainTaskState="true"
            android:label="@string/app_name"
            android:screenOrientation="portrait"
            android:theme="@style/Theme.AppStartLoadTranslucent">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

2, Full screen reserved status bar text (Banner image at the top of the page):

Window window = getWindow();
//Default API minimum 19 
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN_MR2) {
    window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
    ViewGroup contentView = window.getDecorView().findViewById(Window.ID_ANDROID_CONTENT);
    contentView.getChildAt(0).setFitsSystemWindows(false);
}

3, Title bar and status bar are the same color

Configuration in xml:

<style name="status_toolbar_same_color" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/status_toolBar_same_color</item>
    <item name="colorPrimaryDark">@color/status_toolBar_same_color</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>

If the phone is lower than 21, the settings are as follows:

Window window = getWindow();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
    window.setStatusBarColor(getResources().getColor(R.color.status_toolBar_same_color));
} else {
    window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
    ViewGroup systemContent = findViewById(android.R.id.content);
    View statusBarView = new View(this);
    ViewGroup.LayoutParams lp = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, getStatusBarHeight());
    statusBarView.setBackgroundColor(getResources().getColor(R.color.status_toolBar_same_color));
    systemContent.getChildAt(0).setFitsSystemWindows(true);
    systemContent.addView(statusBarView, 0, lp);
}

4, Status bar text color settings

//Set black characters on white background
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
    getWindow().getDecorView()
        .setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
}

In addition, Xiaomi and Meizu, the domestic manufacturers, have also opened the way to modify the font in the status bar:

  • Millet MIUI6

    https://dev.mi.com/doc/p=4769/index.html

  • Meizu Flyme

    http://open-wiki.flyme.cn/index.php?title = status bar changes color

Tags: Android xml Flyme PHP

Posted on Sun, 05 Apr 2020 18:03:28 -0400 by crash4o4