Customizing TextInputLayout – Part 2

TextInputLayout Demo

In previous article Customizing TextInputLayout – Part 1, we learnt how to customize TextInputLayout and how to apply hint color to it.

Going to next step of TextInputLayout, in this article we are going to customize this widget by applying custom Typeface to it.

Change Typeface of TextInputLayout

First what you need to do is, download some decent fonts online. You can also use fonts which I have used in demo by downloading it from here.

After downloading fonts, open your MainActivity.java file. Actually there is no any method to apply custom fonts in XMl layout file. So we need to patch some part of TextInputLayout to apply custom font.

Declare objects and assign ids to them. Here, in my demo, I took 3 TextInputLayout and apply ids like below.

In your activity, code will be like

After declaring objects, you need to write following method inside your activity. Copy paste below code.

All things are done to apply Typeface to TextInputLayout. We have objects, we have typeface files and we have method to apply font. So simply write below single line of code to apply font to TextInputLayout.

Syntax

setTypefaceToInputLayout(textInputObject,"Typeface_File_Name.ttf");

Example

setTypefaceToInputLayout(tilFiratName,"KGCamdenMarketScript.ttf");

Demo



The source code for this article is available here

Summary

In this article, we learnt how to apply custom Typeface to TextInputLayout. You can apply any Typeface to as per your need.

You may also like to read

Read Logs programmatically in Android In this blog you will learn how to read logs programmatically in Android and used for bug report purposes. Its easy to read logs from Logcat an...
NFC Mifare UID (Card Serial Number) reverse issue ... If you are using NFC (Near Field Communication) Mifare in your application, you should be careful while using NFC Mifare UID  (Unique IDentification ...
DevFestAhm – GDGAhmedabad 2015 – Aweso... Google Developer Group is Open for all including students, newbies, developers and anyone for all who are interested in Google technologies. It is Guj...
APK Analysis : Spotlight on WhatsApp | How to use ... Android Studio includes an APK Analyzer that provides immediate insight into the composition of your APK after the build process is complete. In th...
Share on Facebook0Share on Google+1Tweet about this on TwitterShare on LinkedIn1Share on Reddit0Pin on Pinterest0Share on Tumblr0Email this to someone