脚本宝典收集整理的这篇文章主要介绍了Android沉浸式状态栏,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
AndROId沉浸式状态栏
市场上,现阶段很流行Android沉浸式开发,但是限于GOOGLE api的限制,所以此特性只能针对Android4.4,GIThub上目前开源的SystemBarTint能够很好的实现此特性。
沉浸式实现
Android 4.4 特有属性,Android 5.0以上机型,默认开启。
1:利用Android studio 导入 jar 包
dePEndencies {
compile 'com.readystateSoftware.systembartint:systembartint:1.0.3'
}
2:使用SytemBarTintManager
PRotected void setSystemBarTintDrawable(Drawable d) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
SystemBarTintManager mTintManager = new SystemBarTintManager(this);
if (d != null) {
mTintManager.setStatusBarTintEnabled(true);
mTintManager.setTintDrawable(d);
} else {
mTintManager.setStatusBarTintEnabled(false);
mTintManager.setTintDrawable(null);
}
}
}
3:设置状态栏透明
/**
* set status bar translucency
* @param on
*/
protected void setTranslucentStatus(boolean on) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
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);
}
}
4:设置完成
5:温馨提示:
[DEPRECATED] Apply background tinting to the Android system UI when using KitKat translucent modes.
SystemBarTint上已经不支持使用该jar了。
以上是脚本宝典为你收集整理的Android沉浸式状态栏全部内容,希望文章能够帮你解决Android沉浸式状态栏所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。