0

I want to change the button font style when it clicks how can i achieve am new in android please help

   Button b1=(Button)findviewbyid(R.id.login);

how can i select from pre_installed fonts . studio 3.0 has preinstalled fonts

Avinash
  • 361
  • 4
  • 16

2 Answers2

0

You can use this:

Button b1 = (Button) findViewById( R.id.login );
b1.setOnClickListener( new OnClickListener() {

    @Override
    public void onClick(View v) {
        Typeface newFont = getResources().getFont(R.font.myfont);
        b1.setTypeface(newFont);
    }
});
Roberto Pinheiro
  • 1,260
  • 13
  • 30
0

Get the font you need as a .ttf file and place it in your project's /assets/ directory. Use this code to refer to the font and set it to your button:

Typeface face= Typeface.createFromAsset(getAppContext().getAssets(), "LightBlueFont.ttf"); 
button.setTypeface(face);
Hemant Parmar
  • 3,924
  • 7
  • 25
  • 49