夜间模式的切换

//黑夜白天模式切换的配置
attrs
<resources>

    <attr name="bjcolor" format="reference|color"></attr>
    <attr name="txcolor" format="reference|color"></attr>

</resources>

style
<resources xmlns:android="http://schemas.android.com/apk/res/android">

    <style name="fault" parent="@android:style/Theme.Black.NoTitleBar">
        <item name="@attr/bjcolor"> @android:color/white</item>
        <item name="@attr/txcolor">@android:color/black</item>
    </style>

    <style name="Night" parent="@android:style/Theme.Black.NoTitleBar">
        <item name="@attr/bjcolor">@android:color/darker_gray</item>
        <item name="@attr/txcolor">@android:color/white</item>
    </style>

</resources>

//代码的是实现
if (blFlag) {
            this.setTheme(R.style.Night);
            blFlag = false;
            editor.putBoolean("b", false);
        } else {
            this.setTheme(R.style.fault);
            blFlag = true;
            editor.putBoolean("b", true);
        }


原文地址:https://www.cnblogs.com/weiyangge/p/5310574.html