【问题标题】:Confusion on defining custom Style and theme定义自定义样式和主题的困惑
【发布时间】:2014-11-28 08:47:07
【问题描述】:

定义自定义样式,我们这样做

 <?xml version="1.0" encoding="utf-8"?>
<resources>
   <style name="CustomFontStyle" parent="@android:style/TextAppearance">
      <item name="android:layout_width">fill_parent</item>
      <item name="android:layout_height">wrap_content</item>
      <item name="android:capitalize">characters</item>
      <item name="android:typeface">monospace</item>
      <item name="android:textSize">12pt</item>
      <item name="android:textColor">#00FF00</item>/> 
   </style>
</resources>

并定义我们这样做的自定义主题

<style name="CustomTheme" parent="android:Theme.Light">
    ...
</style>

我的困惑是为什么父属性是“android:Theme.Light”而不是@android:style/Theme.Light

任何帮助都会很棒。 谢谢!

【问题讨论】:

    标签: android styles themes


    【解决方案1】:

    “android:Theme.Light”是“@android:style/Theme.Light”的一种短类型,在定义样式或主题时可以使用后者代替前者。

    同样,“@android:style/TextAppearance”也可以缩写为“android:TextAppearance”。

    因为样式的父级必须是样式,所以“样式”一词可以省略,不会误导构建工具。

    请记住,将样式应用于视图或活动时,不能省略“样式”一词。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-28
      相关资源
      最近更新 更多