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

来源:互联网 发布:民可使由之 不可使知之 编辑:程序博客网 时间:2024/05/19 21:02

概述

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,尝试修复找到了这个问题)

原创粉丝点击