简介
Android4.4以后,很多APP的状态栏都不再是黑乎乎的一条,开始出现状态栏和APP同一个颜色,瞬间感觉高大上了啊,这个是怎么实现的呢?
基于Android原生代码实现
需要2步
第一步
新建values-19文件夹,在里面新增一个style.xml,设置其android:windowTranslucentStatus为true内容如下:
<resources>
<style name="AppTheme" parent="@style/BaseAppTheme">
<item name="android:windowTranslucentStatus">true</item>
</style>
</resources>
第二步
在需要显示的布局文件中添加两句话
android:clipToPadding="true"
android:fitsSystemWindows="true"
使用第三方框架SystemBarTint
GIThub上牛人分享的框架SystemBarTint,可以很方便的实现状态栏透明,省去很多步骤
实现步骤如下
第一步
下载jar包点这儿
并导入项目
第二步
在相应的Activity的onCreate方法中添加如下代码
//super.onCreate(savedInstanceState);
//setContentView(R.layout.activity_main);
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;
winParams.flags |= bits;
win.setAttributes(winParams);
SystemBarTintManager mTintManager = new SystemBarTintManager(this);
mTintManager.setStatusBarTintEnabled(true);
mTintManager.setNavigationBarTintEnabled(true);
mTintManager.setTintColor(R.color.colorPrimary);
}