1

我在我的应用程序中使用 HoloEverywhere 库并从主题应用字体我已将新的自定义属性 ttfName 添加到 TextView 样式,并在 org.holoeverywhere.widget.TextView 的构造函数中进行了一些必要的更改,如下所示;

if (a.hasValue(R.styleable.TextView_ttfName)) {
    setTypeface(Typeface.createFromAsset(getContext().getAssets(), "fonts/" +   
    a.getString(R.styleable.TextView_ttfName)));
}

此外,声明的风格和主题如下;

<style name="AppTheme" parent="@style/Holo.Theme.Light.DarkActionBar">                
    <item name="android:textViewStyle">@style/Widget.ApplicationTheme.TextView</item
</style>

<style name="Widget.ApplicationTheme.TextView" parent="@style/Holo.TextView">
    <item name="ttfName">@string/app_font_roboto_light</item>
    <item name="android:textSize">@dimen/app_dimen_default_text_size</item>
</style>

添加的ttfName属性如下;

...
<attr name="ttfName" format="string" />
...
...
<declare-styleable name="TextView">
    <attr name="android:text" />
    <attr name="android:textAllCaps" />
    <attr name="textAllCaps" />
    <attr name="ttfName" />
</declare-styleable>
...

现在,当我将 AppTheme 应用到我的应用程序时,只有在 android 版本 > 4.0(尚未检查 3.0)时才会应用字体。但在 android 版本 2.3 上,字体没有被应用..

有人可以帮我弄清楚这里出了什么问题吗?

提前致谢。

4

1 回答 1

1

它是在 preHC 机器人上不适用于 Holoeverywhere 的字体,preHC 上的 FontLoader 在所有文本视图中加载机器人字体。

对于应用字体,请查看类org.holoeverywhere.FontLoaderFontLoader#apply(View)方法。

于 2013-05-06T04:37:31.973 回答