设置主题颜色/项目

时间:2016-11-14 22:04:33

标签: android themes

我可能对主题如何在android中工作有一个有缺陷的理解,所以我只想说我想做什么,有人可以告诉我为什么我错了:

我希望我的应用程序在黑暗主题和轻主题之间切换,所以我宣布了两个主题。主题切换工作正常,当我想添加一个可能不存在的属性时出现问题:

<style name="AppThemeDark" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">#000</item>
    <item name="colorPrimaryDark">#000</item>
    <item name="colorAccent">#000</item>
    <item name="colorBackground">#000</item>
    ...
</style>

产生结果:No resource found that matches the given name: attr 'colorBackground'.

所以我知道这里有两件事情之一:

  1. 我不知怎的,某处需要定义colorBackground,或者..
  2. 我无法添加任何新属性,必须与我给出的属性一起工作,这对我来说似乎很奇怪,但是,嘿,我知道什么。
  3. 我希望我的两个主题都有一个'colorBackground',以便我可以将应用程序的视图背景设置为相应的主题。浅色主题的浅色背景和黑暗主题的深色背景。理想情况如下:

    <RelativeLayout>
        ....
        android:background="?attr/colorBackground"
        ....
    </RelativeLayout>
    

    可能有一个特定的属性专门用来做这个,但我不知道。

    那么我做错了什么?

0 个答案:

没有答案
相关问题