不爱废话直接上菜。
第一种适配方式:
1.1 直接修改APP主题,values/styles.xml 如下:
<style name="AppTheme" parent="Theme.AppCompat.DayNight.NoActionBar"> <item name="android:forceDarkAllowed">true</item> ... </style> 或者 <style name="AppTheme" parent="Theme.AppCompat.DayNight.DarkActionBar"> <item name="android:forceDarkAllowed">true</item> ... </style>
1.2 修改AndroidManifest.xml中application标签下theme属性
<application android:name=".BaseApplication" android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme"> .... </application>
1.3 说明:通过强制设置黑暗模式,可以使APP进行黑白两色进行反色(个人不推荐这么干)。
第二种适配方式:
2.1 修改APP主题,values/styles.xml 如下(注意这里forceDarkAllowed为false):
<style name="AppTheme" parent="Theme.AppCompat.DayNight.NoActionBar"> <item name="android:forceDarkAllowed">false</item> ... </style> 或者 <style name="AppTheme" parent="Theme.AppCompat.DayNight.DarkActionBar"> <item name="android:forceDarkAllowed">false</item> ... </style>
2.2 修改AndroidManifest.xml中application标签下theme属性
<application android:name=".BaseApplication" android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme"> .... </application>
2.3 颜色适配:在res目录下新建values-night目录,看名字就知道这个目录下的东西会在暗黑模式下生效(一般放colors.xml, styles.xml就可以了)(具体颜色是什么就可以找你们的设计师小伙伴了)。
values/colors.xml
values-night/colors.xml
2.4 图片适配:在res目录下新建mipmap-night-xhdpi / mipmap-night-xxhdpi目录,这些目录下的图片也是在暗黑模式下才生效(图片找设计师小伙伴)。
2.5 比较推荐使用第二种,可以达到与设计师要求的效果一致。
另外给大家一个深色模式适配推荐颜色图
热门文章
- 开一个宠物医院用word文档怎么弄(如何开办宠物医院论文)
- 动物接种疫苗的好处有哪些方面的内容和方法(动物疫苗的作用)
- 2月2日 | Trojan节点订阅每天更新22.3M/S免费节点订阅链接
- 动物疫苗包括哪些类型的(动物疫苗有哪几种)
- win11系统找不到记事本如何解决
- 11月25日 | Trojan节点订阅每天更新22.3M/S免费节点订阅链接
- springboot:异步注解@Async的前世今生_在线工具
- Fastjson tomcat-dhcp链
- 1月4日 | Trojan节点订阅每天更新19.6M/S免费节点订阅链接
- 1月25日 | Trojan节点订阅每天更新20.6M/S免费节点订阅链接