【问题标题】:Where should I put text style in my resources?我应该将文本样式放在我的资源中的什么位置?
【发布时间】:2013-10-24 17:21:15
【问题描述】:

所以我有一个styles.xml,其中包含以下内容:

....
<style name="TextAppearance.CustomTheme.Widget.ActionBar.Menu"
                parent="android:TextAppearance.Holo.Widget.ActionBar.Menu">
    <item name="android:textSize">@dimen/text_size</item>
    <item name="android:textStyle">{text_style}</item>
</style>
...

请注意,text_size 是在dimens.xml 文件中定义的。我需要将 textStyle 值存储在另一个与 textSize 类似的文件中,但我不知道应该把它放在哪里。似乎没有文本样式的资源类型(普通、粗体、斜体)。

我需要将它放在另一个文件中的原因是这样我只能拥有一个styles.xml,然后是多个其他文件(dimens.xmlcolors.xml 等),这些文件会根据屏幕大小而变化,等等,所以我最终在 /values 上只有一个 styles.xml,然后是多个值文件夹(\values-sw480dp、\values-sw720dp)和不同的dimens.xmlcolors.xml 等文件.

此外,我尝试引用如下所示的字符串,但它无效。

<item name="android:textStyle">@string/text_style</item>

【问题讨论】:

    标签: android android-xml android-styles


    【解决方案1】:

    显然这是不可能的。查看TextView's textStyle attribute 参考,它看起来不接受参考,因为该属性的文档没有像其他属性那样说明以下内容:

    这也可能是对资源的引用(形式为 “@[package:]type:name”)或主题属性(形式为 "?[package:][type:]name") 包含此类型的值。

    它只说明它接受的常量(以及它们与 | 的组合)。

    【讨论】:

      【解决方案2】:

      当我在我的 styles.xml 资源文件的 android:textStyle 属性中编写“粗体”时,它起作用了。

      <!-- Base application theme. -->
      <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
          <!-- Customize your theme here. -->
          <item name="colorPrimary">@color/colorPrimary</item>
          <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
          <item name="colorAccent">@color/colorAccent</item>
      </style>
      
      <style name="questionStyle" parent="TextAppearance.AppCompat">
          <style name="android:textStyle">bold</style>
          <style name="android:textSize">18sp</style>
      
      
      </style>
      

      如果那个答案是你的意思。对不起,如果我不明白你的问题。

      【讨论】:

        猜你喜欢
        • 2010-12-04
        • 1970-01-01
        • 2018-03-19
        • 2010-10-11
        • 1970-01-01
        • 1970-01-01
        • 2012-07-22
        • 1970-01-01
        • 2012-11-12
        相关资源
        最近更新 更多