我有一个有 7 个 Activity 的应用程序。所有 Activity 在 main root
元素中都有 1、2、3 或 4 个 root
元素。此 root
元素具有带有相关颜色的深色背景色。我想在我的应用程序中使用浅色主题。因此,我想知道将我的应用程序主题从深色更改为浅色的哪种方法更好、更专业?
- 用我的颜色值为每个“根”元素定义两个主题?如果答案是肯定的,我该如何定义它?示例代码?
- 为每个“根”元素定义样式?
- 或者只是找到我的第 1、2、3 或 4 个“根”元素并使用“选项”菜单设置 UI 更改背景颜色?
谢谢
主题也是样式,因此如果您希望整个应用程序由例如 Holo.light 驱动,您可以简单地定义如下样式并为预定义元素更改所需的颜色和样式,然后在 list 中设置您的应用程序主题:
<style name="MyTheme" parent="@android:style/Theme.Holo.Light">
<item name="progressBarStyle">@android:style/Widget.ProgressBar.Inverse</item>
<item name="progressBarStyleSmall">@android:style/Widget.ProgressBar.Small.Inverse</item>
<item name="progressBarStyleLarge">@android:style/Widget.ProgressBar.Large.Inverse</item>
</style>
但是如果你想为你的 Activity 设置背景颜色并在运行时或通过单击 menuItem 更改它,我认为更好的方法是为你的根元素定义两种样式( Activity 布局中的大多数外部元素)并为这些元素定义背景喜欢:
<style name="LinearLayoutLight">
<item name="android:background">@color/#somecolor</item>
</style>
<style name="LinearLayoutDark">
<item name="android:background">@color/#somecolor</item>
</style>