【发布时间】:2012-03-20 20:36:48
【问题描述】:
我正在尝试在 Android OS 2.3.x 中使用 Java 在列表视图中拥有自己的字体
阅读以下链接后,我被卡住了:
http://developer.android.com/guide/topics/ui/themes.html http://stackoverflow.com/questions/4576441/custom-font-in-android-listview http://androidforums.com/android-lounge/143874-custom-typface-listview-row-layout.html
我不能在这里发布有用的东西。
我的主要问题是:
- 为什么我不能使用 setTypeface 更改列表视图的字体?
- 为什么我不能在我的应用程序中为所有文本定义一个字体而不将它再次放入每个活动中?
- 是否有处理此问题的文档? Android SDK 文档缺乏大量详细信息,例如 otf 字体在哪个版本上工作。
我知道我必须学习很多东西,并且我已经准备好了尽可能多的关于这个主题的书籍。但是经过两天的猜测和尝试,我不得不寻求帮助。
可能有人可以将我推向正确的方向;)
为了给你一个小想法,我尝试清理一些代码:
文件:res/layout/scores.xml (sn-p from it)
<ListView
android:id="@+id/android:list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#00000000"
android:cacheColorHint="#00000000"
android:transcriptMode="disabled" >
</ListView>
文件:src/notneededasinfo/ScoresActivity.java (sn-p from it)
Resources myResources = getResources();
Typeface tf = Typeface.createFromAsset(myResources.getAssets(),"fonts/searstower.ttf");
TextView tv = (TextView) findViewById(android.R.id.list);
tv.setTypeface(tf);
谢谢帮助!
【问题讨论】:
-
@您的代码显示一些错误?或者是什么问题?
-
问题是,我没有得到任何异常或错误,并且字体没有改变。我想,这只是我这边的一个小问题,就像一个错字。
-
只需将这个 myResources.getAssets() 修改为 getApplicationContext().getAssets() 并尝试。