An Easy Way For Android Developers To Set Font Styles for TextViews
This Small Piece of development should assist developers in setting typefaces for TextView/TextViews and also take off the
stress of always trying to Call on Typeface.createFromAsset(....);
on every Textview
or an Instance of TextView e.g Buttons.
To set the TypeFace for a particular TextView instance all you need do is :
TextView myTextView = (TextView) findViewById(R.id.myText);
FontStyleFactory.setFontForView(context, myTextView, StyleConstants.GENERAL_APP_FONT);
To set the TypeFace for a group of TextView instance all you need do is :
Initialize all Your TextView Instance First.
setHbFirstName((EditText)findViewById(R.id.hb_sign_up_first_name));
setHbLastName((EditText)findViewById(R.id.hb_sign_up_last_name));
setHbEmailAddress((EditText)findViewById(R.id.hb_sign_up_email));
setHbMobileNumber((EditText)findViewById(R.id.hb_sign_up_mobile));
setHbPassword((EditText)findViewById(R.id.hb_sign_up_password));
setHbSignUpBtn((Button)findViewById(R.id.hb_sign_up_btn));
setHbSex((Spinner)findViewById(R.id.hb_sign_up_sex));
setHbDateOfBirth((EditText)findViewById(R.id.hb_sign_up_dob));
setHbAddress((EditText)findViewById(R.id.hb_sign_up_address));
View[] views = {hbFirstName, hbLastName,hbEmailAddress, hbMobileNumber, hbSignUpBtn, hbPassword,hbSex, hbDateOfBirth, hbAddress};
FontStyleFactory.setFontForAllViews(this, views, StyleConstants.GENERAL_APP_FONT);
NOTE
The StyleConstants should only contain static String
variable
which holds values of a TFF (font files) file name in the android asset directory.