Android资源文件夹下面values/style.xml、values-v19/style.xml、values-v21/style.xml主题调用规则

概述

values-v19/style.xml—对应api19+手机型号在此调用。
values-v21/style.xml—对应api21+手机型号在此调用。
values/style.xml—对应values-v19和values-v21的style.xml中没有对应主题时默认在此调用。

关注点

以沉浸式通知栏主题ColorTranslucentTheme,继承AppCompatActivity为例。
沉浸式主题有两种写法:
方法一:
values/style.xml

<style name="ImageTranslucentTheme" parent="AppTheme">
<!--Android 4.4之前的版本上运行,直接跟随系统主题-->

</style>

values-v19/style.xml

<style name="ImageTranslucentTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="android:windowTranslucentStatus">true</item>
    <item name="android:windowTranslucentNavigation">true</item>
</style>

values-v21/style.xml

<style name="ImageTranslucentTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="android:windowTranslucentStatus">false</item>
    <item name="android:windowTranslucentNavigation">true</item>
    <!--Android 5.x开始需要把颜色设置透明,否则导航栏会呈现系统默认的浅灰色-->
    <item name="android:statusBarColor">@android:color/transparent</item>
</style>

方法二:
values/style.xml

<style name="ColorTranslucentTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <item name="android:windowTranslucentStatus" tools:targetApi="kitkat">true</item>
        <item name="android:windowTranslucentNavigation" tools:targetApi="kitkat">true</item>
        <item name="android:statusBarColor" tools:targetApi="lollipop">@android:color/transparent</item>
</style>

自己项目中使用哪种方法都可以,但如果你的项目作为另一个项目的aar就要注意了:
要与主项目的使用方法相同。
(有次要实现ios样式的沉浸式通知栏,我运用方法一来实现的,测试没问题,但作为aar导入另一个项目后在android4.1手机上出现了Crash,尝试修复找到了这个问题)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值