Android沉浸式Translucent System Bar

Android沉浸式布局实践
本文介绍了如何实现Android应用的沉浸式布局,主要适用于API 19及以上的版本,并提供了针对不同版本的适配方案。通过修改styles.xml文件,可以轻松实现状态栏及虚拟按键的背景颜色自定义。

Android沉浸式Translucent System Bar

Android沉浸式APP主要是用在Android 4.4以上才会有效果。 也就是api-19+

什么是沉浸式。 如下图:

JAVA icon

可以看到第一幅图上面的状态栏和底下的虚拟按键都变成蓝色,比第二张图效果好一些。所以这个就是沉浸式效果

沉浸式效果只能支持Android api 19以上也就是 Android 4.4以上。但是低版本的适配怎么办。

请注意我们可以建立 3个文件夹分别为value value-v19 value-v21 来进行适配

  • value 代表适配Android4.4以前的,styles.xml内容如下:
<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <!--Theme.AppCompat.Light.DarkActionBar-->
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>
</resources>

  • value-v19 适配api-19 Android4.4以上。

<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <!--Theme.AppCompat.Light.DarkActionBar-->
        <!-- 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:windowTranslucentStatus">false</item>
        <item name="android:windowTranslucentNavigation">false</item>
    </style>
</resources>
  • value-v21 适配Android5.0以上。

转载于:https://my.oschina.net/u/1175746/blog/757626

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值