shani aamir
shani aamir

Reputation: 1

How to apply a specific font to EditText?

I am new to android development, I need to implement Rich text Editor in my Application. So i googled and found some solutions. I am using this solution:

http://code.google.com/p/android-richtexteditor/source/browse/?r=4#svn/trunk/src/net/sgoliver

It supports the Bold, Italic and Underline in it. Now I want to change the font-style of selected text in EditText, How do i do that?

I know how to set the font-style for all the text in EditText. Suggestions will be appriciated!

Upvotes: 0

Views: 1161

Answers (4)

Anu
Anu

Reputation: 1914

Copy the font files (*.ttf) to the assets folder of your application.

Consider I have copied the font file "verdana.TTF" to the assets folder, then the following code will set the font to verdana

EditText et=(EditText) findViewById(R.id.editText1);
Typeface tf =   Typeface.createFromAsset(getAssets(),"verdana.TTF");
et.setTypeface(tf);

Hope you got the solution

Upvotes: 2

Ketan Ahir
Ketan Ahir

Reputation: 6738

try this code..create font folder like this assets/font and put your font file in it..

 edittxt = (EditText) findViewById(R.id.edittxt);

 Typeface myTypeface = Typeface.createFromAsset( this.getAssets(), "font/YOURFONT.otf");

 edittxt.setTypeface(myTypeface);    

Upvotes: 0

Ram kiran Pachigolla
Ram kiran Pachigolla

Reputation: 21191

Typeface tf =   Typeface.createFromAsset(getAssets(),"fonts/Comic.ttf");
EditText et =   (EditText)findViewById(R.id.et);
et.setTypeface(tf);

you can place ttf file in assets and set font style here

Upvotes: 0

swiftBoy
swiftBoy

Reputation: 35783

editText.setTypeface(Typeface.SERIF); as like as TextView.

Upvotes: 0

Related Questions