To use this library, you first need to add dependencies:
compile 'org.zackratos:ultimatebar:1.0.3'
Custom color status bar and navigation bar
To set a custom color for the status bar and navigation bar, just call the following code in the onCreate method:
UltimateBar ultimateBar = new UltimateBar(this); ultimateBar.setColorBar(ContextCompat.getColor(this, R.color.DeepSkyBlue));
Translucent status bar and navigation bar
The use of translucent status bar and navigation bar is also very simple, just call the following code in the onCreate method:
UltimateBar ultimateBar = new UltimateBar(this); ultimateBar.setTransparentBar(Color.BLUE, 50);
Fully transparent status bar and navigation bar
In fact, the fully transparent status bar and navigation bar are the translucent status bar and navigation bar when the transparency is 0, just call the following method in the onCreate method:
UltimateBar ultimateBar = new UltimateBar(this); ultimateBar.setImmersionBar();
Hide status bar and navigation bar
This situation is relatively common. Generally, playing games and watching videos is the effect. The realization of this effect is a bit special. The onWindowFocusChanged method of Activity must be rewritten, as follows:
@Override public void onWindowFocusChanged(boolean hasFocus) { super.onWindowFocusChanged(hasFocus); if (hasFocus) { UltimateBar ultimateBar = new UltimateBar(this); ultimateBar.setHintBar(); } }
Implementation for DrawerLayout
There is also a special case, that is, for DrawerLayout, the above method will have some problems and cannot achieve the desired effect, here is a special treatment for DrawerLayout, in general, for DrawerLayout, as long as the status bar and navigation of custom colors are implemented The effect of the column is good, and other situations do not need to be considered. You can call the following code in onCrate:
UltimateBar ultimateBar = new UltimateBar(this);
ultimateBar.setColorBarForDrawer(ContextCompat.getColor(this, R.color.DeepSkyBlue));
But this is not enough. It is also necessary to add android:fitsSystemWindows="true" to the main interface of the sub-view of DawerLayout in the layout file, like this:
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:orientation="vertical">
</LinearLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/SpringGreen"
android:layout_gravity="left"/>
</android.support.v4.widget.DrawerLayout>