我应该在哪里将文字样式放在我的资源中?

时间:2013-10-24 17:21:16

标签: android android-xml android-styles

所以我有一个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,然后在不同的{{1}处有多个值文件夹(\ values-sw480dp,\ values-sw720dp) },dimens.xml等文件。

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

colors.xml

2 个答案:

答案 0 :(得分:2)

显然不可能这样做。查看TextView's textStyle attribute引用它看起来它不接受引用,因为此属性的文档没有说明以下内容,正如其他属性所做的那样:

  

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

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

答案 1 :(得分:0)

当我在styles.xml资源文件中的android:textStyle属性中编写“bold”时,它工作正常。

<!-- 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>

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