Reputation: 63
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.
My main problems are:
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 someone can push me in the right direction ;)
To give you a small idea, i tried to clean up some code:
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>
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 for help!
Upvotes: 1
Views: 2838
Reputation: 121
Well... first of all android:textStyle and setTypeface(Typeface) are not a property and function from ListView, it is from TextView.
Try to use this tutorial: http://developer.android.com/resources/tutorials/views/hello-listview.html
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));
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...
Upvotes: 1
Reputation: 846
I have a answer for one of your questions
Why can't i define a Font for ALL texts in my application without putting it in every activity again?
This is a known problem but easy to solve. Just implement a custom activity class which extends Activity and overwrite the setContentView()
method. In this Method you can get all your TextViews for your current view and set the Typface
See here: Add custom font for complete android application
Upvotes: 0
Reputation: 13808
TextView tv = (TextView) findViewById(android.R.id.list);
You need to have a text view to set the font. You are missing the list row view.
Upvotes: 0