android - 主题、样式还是硬编码?

标签 android android-theme android-styles

<分区>

我有一个有 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>

关于android - 主题、样式还是硬编码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24880707/

相关文章:

android - 如何在整个主题中更改 AppBarLayout 的样式?

android - _HoloActivity$HoloThemeException : You must apply Holo. 主题,Holo.Theme.Light 或 Holo.Theme.Light.DarkActionBar 主题

android - 在 Android < 4.0 上使用全息主题

android - ActionBar 样式不起作用

java - 如何从日期时间字符串中获取时区

Android DatePickerDialog 强调色(在 v21+ 中)

android-如何像这样添加底部边框

android - 当 subview 的内容更改时, ScrollView 不会调整大小

android - 我想把按钮( subview )放在android的前面

android - 如何提高 Android 中的 GPS 定位精度