android 沉浸式主题记录

本文详细介绍了两种实现Android沉浸式主题的方法:一是通过代码直接设置,二是利用style进行适配,包括在values-v21文件夹中创建theme以及在AndroidManifest.xml中应用该theme。
摘要由CSDN通过智能技术生成

方式一:代码设置

if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP){//判断系统版本5.0以上
            Window window = this.getWindow();
            window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
//            window.setStatusBarColor(0xff01c7d4);
            //顶部状态栏设置根布局的背景色 也可以设置某个view的背景色
            window.setStatusBarColor(activity_offline_help.getDrawingCacheBackgroundColor());
            //底部导航栏设置根布局的背景色 也可以设置某个view的背景色
            window.setNavigationBarColor(activity_offline_help.getDrawingCacheBackgroundColor());
        }

方式二:style适配

1.创建一个values-v21文件夹

2.写入theme

<style name="AppBaseTheme" parent="Theme.AppCompat.Light.DarkActionBar">

    <item name="android:windowTranslucentStatus">false</item>
    <!--<item name="android:windowTranslucentNavigation">true</item>-->!<!--底部导航条 透明-->
    <!--Android 5.x开始需要把颜色设置透明,否则导航栏会呈现系统默认的浅灰色-->
    <item name="android:statusBarColor">@color/app_title</item>
    <item name="android:fitsSystemWindows">true</item><!--导致dialog 边框内陷-->
</style>

3.在manifest中应用

<activity
    android:name=".activity.StorageSetActivity"
    android:screenOrientation="portrait"
    android:theme="@style/AppBaseTheme" />




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值