可以实现根据用户自己选择切换对应的样式,也可以根据时间切换样式(比如白天样式跟晚上的样式)
效果样式
attr.xm文件中的代码
<?xml version="1.0" encoding="utf-8"?>
<resources>
<attr name="myBgColor" format="reference" />
<attr name="myButtonColor" format="color" />
<attr name="myTextColor" format="color" />
<attr name="myTextSize" format="reference" />
</resources>
在styles.xm文件中增加各个主题样式(这里面的name是使用的额是attr里面自己定义的字段)
<!--正常主题-->
<style name="LightTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="myBgColor">@color/colorPrimaryDark</item>
<item name="myTextColor">@color/black</item>
<item nam