PrivateButton Sbutton; PrivateTextView Mtextview; PrivateButton Fbutton; Private int[] sarray={ -, -, -, the, the}; @Overrideprotected voidonCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (r.layout.activity_ex0313); Mtextview=(TextView) Findviewbyid (ID. Ex0313displaytext); Sbutton=(Button) Findviewbyid (ID. Ex0313sizebutton); Sbutton.setonclicklistener (NewButton.onclicklistener () {@Override Public voidOnClick (View v) {//TODO auto-generated Method StubRandom mrandom=NewRandom (); intMnum = Mrandom.nextint (4); Mtextview.settextsize (Sarray[mnum]); } }); Fbutton=(Button) Findviewbyid (ID. Ex0313fontsbutton); Fbutton.setonclicklistener (NewButton.onclicklistener () {@Override Public voidOnClick (View v) {//TODO auto-generated Method StubTypeface Ftypeface=typeface.createfromasset (Getresources (). Getassets (),"Fonts/pentagram ' Smalefissent.ttf"); Mtextview.settypeface (Ftypeface); } }); }
<TextView android:layout_width="wrap_content"Android:layout_height="wrap_content"Android:id="@+id/ex0313displaytext"Android:layout_marginleft="20DP"Android:layout_margintop="10DP"Android:text="@string/hello_world"/><button android:id="@+id/ex0313sizebutton"Android:layout_width="wrap_content"Android:layout_height="wrap_content"Android:layout_marginleft="20DP"Android:layout_margintop="50DP"Android:text="@string/ex0313sizebutton"/><button android:id="@+id/ex0313fontsbutton"Android:layout_width="wrap_content"Android:layout_height="wrap_content"Android:layout_marginleft="20DP"Android:layout_margintop="100DP"Android:text="@string/ex0313fontsbutton"/>
Android Entry-activity and fonts