开发者

How to change the Font styles and face in Android?

开发者 https://www.devze.com 2023-04-06 20:58 出处:网络
I want to change the font face and styles in android. How to do this? Am using emulator. Is this possible to change in emulator. Is there any permissi开发者_Go百科ons available to do that. Thanks in A

I want to change the font face and styles in android. How to do this? Am using emulator. Is this possible to change in emulator. Is there any permissi开发者_Go百科ons available to do that. Thanks in Advance.


in android only five fonttype-face

TypeFace

Typeface.DEFAULT
Typeface.MONOSPACE
Typeface.SANS_SERIF
Typeface.DEFAULT_BOLD
Typeface.SERIF

and font-type

Typeface.NORMAL
Typeface.BOLD
Typeface.BOLD_ITALIC
Typeface.ITALIC

you can use like as

textView.setTypeface(Typeface.DEFAULT, Typeface.BOLD);

and other way is you can download any .ttf file and put it in asset folder and use like as this

Typeface type=Typeface.createFromAsset(context.getAssets(),
        "DroidSansMono.ttf");
textView.setTypeface(type, null);


You can change the font style and font face in your XML files. For example if you want to change your Button's style and face. Choose your button in xml and follow the below methods :

Button -> Right Click -> Properties -> Typeface and style

Hope this will help you.


If you want to change in code ;

This is good reference;

http://mobile.tutsplus.com/tutorials/android/customize-android-fonts/


what you want?. Do you want to change the font face and styles of text in textview. if yes then use this

Typeface type = Typeface.createFromAsset(this.getAssets(),"your font name");
text.setTypeface(type);

and for styles use these links:

  1. Style-resource

  2. Themes


If you want to use a font which is not default (like "Helvetica") for the text in Android application then put the font file(Helvetic.ttf) in assets folder and do use this code as below:

Typeface tf= Typeface.createFromAsset(getAssets(), "Helvetica.ttf");
  TextView mTextView =(TextView) findViewById(R.id.text);
    mTextView.setTypeface(tf);


if u want to use custom font jus download .ttf file and put the file into assets folder and use like this:

TextView tv=(TextView)findViewById(R.id.textView);
Typeface  tf = Typeface.createFromAsset(getActivity().getAssets(), "fonts/arial.ttf");
tv.setTypeface(tf);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号