Android 实现夜间模式
2016-02-01 21:24
651 查看
方法1
建一个 value-night 的文件夹,colors.xml如下:<resources> <color name="colorPrimary">#7D4112</color> <color name="colorPrimaryDark">#7D4112</color> <color name="colorAccent">#1F1F1F</color> </resources>
@Override public boolean onNavigationItemSelected(MenuItem menuItem) { int id = menuItem.getItemId(); switch (id) { case R.id.nav_setting: Toast.makeText(this, "夜间模式", Toast.LENGTH_LONG).show(); if (isNightMode) { uiManager.enableCarMode(0); uiManager.setNightMode(UiModeManager.MODE_NIGHT_YES); isNightMode = !isNightMode; } else { uiManager.disableCarMode(0); uiManager.setNightMode(UiModeManager.MODE_NIGHT_NO); isNightMode = !isNightMode; } return true; default: return true; } }
但是这种方法会开启车载模式
在笔者的测试机(红米1s)中,这种方法会先退出应用,再启动应用已经是夜间模式
注意点
CardView 的背景色是app:cardBackgroundColor="?attr/windowBackground"设置,不是普通的
android:background
相关文章推荐
- java对世界各个时区(TimeZone)的通用转换处理方法(转载)
- java-注解annotation
- java-模拟tomcat服务器
- java-用HttpURLConnection发送Http请求.
- java-WEB中的监听器Lisener
- 使用C++实现JNI接口需要注意的事项
- Android IPC进程间通讯机制
- Android Manifest 用法
- [转载]Activity中ConfigChanges属性的用法
- Android之获取手机上的图片和视频缩略图thumbnails
- Android之使用Http协议实现文件上传功能
- Android学习笔记(二九):嵌入浏览器
- android string.xml文件中的整型和string型代替
- i-jetty环境搭配与编译
- android之定时器AlarmManager
- android wifi 无线调试
- Android Native 绘图方法