0

I am a noob. I've seen some of the solutions here, and that just bounced above my head. Can anyone please help me setting up a font in the button? Also, if I can make it italic, bold etc. Here's my XML code

  <Button
    android:id="@+id/button1"
    android:layout_width="60dp"
    android:layout_height="40dp"
    android:layout_alignBottom="@+id/tableLayout1"
    android:layout_alignRight="@+id/relativeLayout1"
    android:background="@drawable/crea"
    android:textSize="30sp"
    android:textColor="#ff0000"/>
Aijaz
  • 680
  • 15
  • 42

1 Answers1

1

You cannot use comic sans MS without purchasing a license:

https://learn.microsoft.com/en-us/typography/font-redistribution-licensing

There are free similar fonts available:

https://fontlibrary.org/en/font/comic-relief

Basic operation in using a different font is to add the font file to the assets folder in the project then use setTypeface on the widget:

Typeface font = Typeface.createFromAsset(getAssets(), "ComicRelief.ttf");
Button bt=(Button) findViewById(R.id.button0);
bt.setTypeface(font);

Full info on using fonts here:

https://tekeye.uk/android/examples/android-textview-edittext-font

Daniel S. Fowler
  • 1,982
  • 15
  • 12
  • I added it in the asset folder. Also, added in the code. Here is how it looks. @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Typeface font = Typeface.createFromAsset(getAssets(), "TickingTimebombBB.ttf"); TextView tv=(TextView) findViewById(R.id.textView1); tv.setTypeface(font); } But how do I use it later? When I go to the properties of the textview, I only see the default values. I also saved the code and checked, it still doesn't show up? – Aijaz Nov 05 '13 at 12:14