Android phone status bar

1. Full screen does not retain the 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);
//全屏展示
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        Timer timer = new Timer();// 实例化Timer类
        timer.schedule(new TimerTask() {
            public void run() {
                Intent intent = new Intent(WelcomeActivity.this,
                        MainActivity.class);
                startActivity(intent);
                finish();
            }
        }, 3000);// 五百毫秒
    }

}

How to remove the white splash screen in the welcome page:

To solve the splash screen, 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 minifist.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. Retain the text of the status bar in the full screen (there is a Banner image on the upper part of the page) :

Window window = getWindow();
//默认API 最低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. The color of the title bar and the status bar is the same

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 you are on a phone lower than version 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);
}

Fourth, the status bar text color settings

//设置白底黑字
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
    getWindow().getDecorView()
        .setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
}

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

  • Xiaomi MIUI6

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

  • Meizu Flyme

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

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325298670&siteId=291194637