安卓:在ListView中自设字体 [英] Android: Own Font in ListView

查看:166
本文介绍了安卓:在ListView中自设字体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想有在Android操作系统2.3.x版本使用Java一个ListView我自己的字体

I'm trying to have my own font in a listview using Java in Android OS 2.3.x

阅读下面的链接后,却困:

After reading the following links, i'm stuck:

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

我不能发布有用的东西在这里。

i can't post something usefull here.

我的主要问题是:


  • 为什么我不能改变字体的列表视图,使用setTypeface?

  • 为什么我不能定义字体在我的应用程序中所有的文本,而不把它在每一个活动着?

  • 是否有一个文档,它可以处理这个问题呢? Android的SDK文档是缺乏庞大的细节量,如在哪个版本OTF字体都在工作。

我知道,我必须学习很多东西,我已经准备好为这个主题的书多,因为我可以。但两天猜测,并试图左右后,我一定要寻求帮助。

I know that i have to learn many things and i'm ready as much books about this topics as i can. But after two days guessing and trying around, i have to ask for help.

Propably有人可以把我在正确的方向;)

Propably someone can push me in the right direction ;)

要给你一个小想法,我试图清理一些code:

To give you a small idea, i tried to clean up some code:

文件:RES /布局/ scores.xml(从中片段)

File: res/layout/scores.xml (snippet 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(从中摘录)

File: src/notneededasinfo/ScoresActivity.java (snippet 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);

THX的帮助!

Thx for help!

推荐答案

嗯...首先所有Android:TEXTSTYLE和setTypeface(字体)不能从一个的ListView性能和功能,它是从的TextView

Well... first of all android:textStyle and setTypeface(Typeface) are not a property and function from ListView, it is from TextView.

尝试使用本教程: http://developer.android。 COM /资源/教程/视图/ HELLO-listview.html

不管怎样,你必须定义定义样式ListView中的一个itens .xml文件。在我张贴之前,你可以在题目4看到该链接的处理程序的OnCreate以下行:

Anyway, you have to define a .xml file that defines the style for the itens in the ListView. At the link I posted before you can see on topic 4 the handler onCreate the following line:

setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item, COUNTRIES));

所以,你必须定义布局上面作为R.layout.list_item文件list_item.xml的ListView项。在这个文件中,list_item.xml,您可以定义新的TextViews或EditTexts或任何与individualy改变字体为每个视图。

So, you have to define the layout for the ListView item on the file list_item.xml used above as R.layout.list_item. On this file, list_item.xml, you define new TextViews or EditTexts or whatever and changes the fonts individualy for each View.

希望它可以帮助你......

Hope it helps you...

这篇关于安卓:在ListView中自设字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆