UltimateBar
透明状态栏导航栏、沉浸式状态栏导航栏的终极解决方案
特点:
1.四种效果,自定义颜色的状态栏和导航栏,半透明状态栏和导航栏, 沉浸式状态栏和导航栏,隐藏状态栏和导航栏;
2.可以自定义状态栏和导航栏的颜色和透明度;
3.KITKAT(Android 4.4)和LOLLIPOP(Android 5.0)上显示效果高度统一。
使用方法:
首先添加依赖:
compile 'org.zackratos:ultimatebar:1.0.3'
1.自定义颜色的状态栏和导航栏
在 onCreate() 方法中:
UltimateBar ultimateBar = new UltimateBar(this);
ultimateBar.setColorBar(ContextCompat.getColor(this, R.color.DeepSkyBlue));
如果需要设置不透明度:
UltimateBar ultimateBar = new UltimateBar(this);
ultimateBar.setColorBar(ContextCompat.getColor(this, R.color.SpringGreen), 50);
2.半透明状态栏和导航栏
在 onCreate() 方法中:
UltimateBar ultimateBar = new UltimateBar(this);
ultimateBar.setTransparentBar(Color.BLUE, 50);
3.沉浸式状态栏和导航栏:
在 onCreate() 方法中:
UltimateBar ultimateBar = new UltimateBar(this);
ultimateBar.setImmersionBar();
4.隐藏状态栏和导航栏:
在 onWindowFocusChanged() 方法中:
@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
if (hasFocus) {
UltimateBar ultimateBar = new UltimateBar(this);
ultimateBar.setHintBar();
}
}
5.在 DrawerLayout 中设置自定义颜色的状态栏和导航栏:
首先需要设置 DrawerLayout 下面的主局部中添加 android:fitsSystemWindows=”true”:
<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>
注意是 DrawerLayout 下面的主布局,DrawerLayout 本身和抽屉布局都不能添加。
然后在 onCreate() 方法中:
UltimateBar ultimateBar = new UltimateBar(this);
ultimateBar.setColorBarForDrawer(ContextCompat.getColor(this, R.color.DeepSkyBlue));
如果需要设置不透明度:
UltimateBar ultimateBar = new UltimateBar(this);
ultimateBar.setColorBarForDrawer(ContextCompat.getColor(this, R.color.DeepSkyBlue), 50);
好了,别人的我转载一下,有什么不会的仔细看楼,挺简单的。。。