android - Multiple custom fonts for multiple textview -
one of app activity include many textview want set multiple custom font textviews,
i tried below code doesn't work customize textview ,
any appreciated
public class text extends activity { /** called when activity first created. */ @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.main); textview tv2=(textview)findviewbyid(r.id.text2); tv2.settext(html.fromhtml(getstring(r.string.text_2))); textview tv3=(textview)findviewbyid(r.id.text3); tv3.settext(html.fromhtml(getstring(r.string.text_3))); textview tv4=(textview)findviewbyid(r.id.text4); tv4.settext(html.fromhtml(getstring(r.string.text_4))); textview tv5=(textview)findviewbyid(r.id.text5); tv5.settext(html.fromhtml(getstring(r.string.text_5))); } class mytextview extends textview { private string textview; public mytextview(context context,int string) { super(context ); } public mytextview(context context) { super(context); } public void settypeface(typeface tf, int string) { if (textview == "tv2,tv4") { super.settypeface(typeface.createfromasset(getcontext().getassets(), "bfantezy.ttf")); } else if (textview == "tv3,tv5") { super.settypeface(typeface.createfromasset(getcontext().getassets(), "rosenewb.ttf")); } } } }
main.xml:
<?xml version="1.0" encoding="utf-8"?> <scrollview xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content"> <linearlayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <textview android:id="@+id/text2" android:layout_width="fill_parent" android:layout_height="wrap_content" android:textsize="25sp"/> <view android:layout_width="fill_parent" android:layout_height="2dp"/> <textview android:id="@+id/text3" android:layout_width="fill_parent" android:layout_height="wrap_content" android:textsize="25sp"/> <view android:layout_width="fill_parent" android:layout_height="2dp"/> <textview android:id="@+id/text4" android:layout_width="fill_parent" android:layout_height="wrap_content" android:textsize="25sp"/> <view android:layout_width="fill_parent" android:layout_height="2dp"/> <textview android:id="@+id/text5" android:layout_width="fill_parent" android:layout_height="wrap_content" android:textsize="25sp"/> </linearlayout> </scrollview>
you comparing in wrong way.. instead
if (getid() == r.id.text2) super.settypeface(typeface.createfromasset(getcontext().getassets(), "bfantezy.ttf"));
and create textview using mytextview.
and compare all.
Comments
Post a Comment