在BaseActivity中
@Override
public void setContentView(int layoutResID) {
super.setContentView(layoutResID);
if (CommonPref.getIsNightMode()) {
addNightView();
} else {
removeNightView();
}
}
protected void addNightView() {
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
LayoutInflater inflater3 = LayoutInflater.from(this);
nightView = inflater3.inflate(R.layout.layout_night, null);
nightView.setLayoutParams(lp);
((ViewGroup) getWindow().getDecorView()).addView(nightView);
}
protected void removeNightView() {
if (nightView!=null){
((ViewGroup) getWindow().getDecorView()).removeView(nightView);
}
}
<?xml version="1.0" encoding="utf-8"?>
<View xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/nightmode"
style="@style/night_mode_style" />
<!-- 夜间模式 -->
<style name="night_mode_style">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">match_parent</item>
<item name="android:background">#b2000000</item>
</style>
Android添加夜间模式---add一层view
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
推荐阅读更多精彩内容
- Java中最常见的装饰者模式应用就是IO流的设计了。先简单回顾一下装饰者模式: 装饰者模式的思想就是在被包装者原有...
- Caused by: android.view.WindowManager$BadTokenException: ...
- 1,错误分析: 从错误信息我们也可以明白其原因,此问题根本原因就是由于将要弹出的dialog所要依附的View已经...