I want to change the Font of List view items to marathi, I use Typeface to change the font of TextField, can anybody tell me how to do it with List View Items..
Asked
Active
Viewed 602 times
0
-
this has already been answered so many times... : http://stackoverflow.com/questions/12128331/how-to-change-fontfamily-of-textview-in-android http://stackoverflow.com/questions/2973270/using-a-custom-typeface-in-android http://stackoverflow.com/questions/3651086/android-using-custom-font http://stackoverflow.com/questions/16901930/memory-leaks-with-custom-font-for-set-custom-font and so on... – Cehm Sep 27 '13 at 08:53
2 Answers
2
Create a custom textView Class like this
public class CustomTextView extends TextView {
public CustomTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init();
}
public CustomTextView(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public CustomTextView(Context context) {
super(context);
init();
}
@SuppressWarnings("null")
private void init() {
if (!isInEditMode()) {
// default style
Typeface tf = Typeface.createFromAsset(getContext().getAssets(),
"helveticaneue_bold.ttf");
setTypeface(tf);
}
}
Place your font style (Marathi.ttf file, in this case i have used helveticaneue_bold.ttf ) in assets folder.
Now in your row, which you have inflated to ListView , instead of TextView use below
<yourpackagename.CustomTextView
android:id="@+id/tv_title"
style="@style/buttontext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/company_profile" >
</yourpackagename.CustomTextView>

Jitender Dev
- 6,907
- 2
- 24
- 35
-
Warning, the method is know to have memory leaks. You might want to load it only once per application and reuse the one you just loading, not reload it again. Consider using your ‘Application.java‘ to load the font, then store it in memory (hashmap or whatever you want) and the reuse it using a single method call. – Cehm Sep 27 '13 at 08:01
-
sir I create that class file, but in which file that xml code I suppose to write – SHRIRANG Sep 27 '13 at 09:37
-
You must have used a row , which is inflated in adapter of listView. you should have something like this View rowView = inflater.inflate(R.layout.rowlayout, parent, false); in your getView method. – Jitender Dev Sep 28 '13 at 03:17
0
You must implement CustomAdapter or BaseAdapter to achieve this. In getview method inflate other xml file which containing textview and settypeface to it

NARESH REDDY
- 682
- 4
- 11