注本文只用作个人记忆,不做其他用途
1、内容延伸至状态栏之上,并不是改变状态栏颜色
<!-- Base application theme. -->
<style name="BaseAppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:screenOrientation">portrait</item>
<item name="android:windowTranslucentStatus" tools:targetApi="kitkat">true</item>
<item name="android:windowTranslucentNavigation" tools:targetApi="kitkat">true</item>
</style>
<style name="BaseAppTheme.Trans">
<!--<item name="android:windowBackground">@android:color/transparent</item>-->
<item name="android:windowIsTranslucent">true</item>
</style>
//清单文件配置
<activity android:name=".ui.splash.SplashActivity"
android:theme="@style/BaseAppTheme.Trans">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
这是4.4系统的截图,状态栏有黑色阴影,5.0效果要好一点,但是有一个缺陷
这一部分就是需要在布局中算到你的title高度中,否则title上的字会与电池重叠
2、改变状态栏颜色
// TODO:适配4.4
@TargetApi(Build.VERSION_CODES.KITKAT)
protected void setStatusBarTranslucent() {
if ((Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT)) {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
//下面三句都是需要导入三方库的
//compile 'com.readystatesoftware.systembartint:systembartint:1.0.3'
SystemBarTintManager tintManager = new SystemBarTintManager(this);
tintManager.setStatusBarTintEnabled(true);
tintManager.setStatusBarTintResource(R.color.colorPrimary);
}
}
<activity android:name=".ui.home.HomeActivity"
android:theme="@style/BaseAppTheme">
</activity>
这里进行区分写成两种颜色,在应用中一般都是颜色相同的
…..后续,边码代码边记