Implement immersive title bar for android4.4
Check the websites and summarize the two feasible methods based on your time.
1. Modify the style file:
1. Add the values-v19 folder and add the following to styles. xml:
Ii. Use open-source libraries
1. Add dependencies to android studio:
compile 'com.readystatesoftware.systembartint:systembartint:1.0.3'
2. Call the following method in onCreate () of the activity:
/** * Apply KitKat specific translucency. */ private void applyKitKatTranslucency() { // KitKat translucent navigation/status bar. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { setTranslucentStatus(true); SystemBarTintManager mTintManager = new SystemBarTintManager(this); mTintManager.setStatusBarTintEnabled(true); mTintManager.setNavigationBarTintEnabled(true); // mTintManager.setTintColor(0xF00099CC); mTintManager.setTintDrawable(UIElementsHelper .getGeneralActionBarBackground(this)); } } @TargetApi(19) private void setTranslucentStatus(boolean on) { Window win = getWindow(); WindowManager.LayoutParams winParams = win.getAttributes(); final int bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS; if (on) { winParams.flags |= bits; } else { winParams.flags &= ~bits; } win.setAttributes(winParams); }
At the end of using the above two methods, you must add them to the main layout:
android:fitsSystemWindows="true"
Otherwise, the title bar is white.