Customizing TextInputLayout – Part 1

customizing textinputlayout

In previous article TextInputLayout – Material Design Support library Tutorial, we learn what is TextInputLayout and what is functionality of it. How TextInputLayout added a new functionality to EditText. Going to next step of TextInputLayout, in this article we are going to customize TextInputLayout.

In this article, we are going do following things.

  • Changing color of hint of TextInputLayout
  • Change Typeface of TextInputLayout

These two customization are very handy in day life application development. Let starts with first one. Changing typeface will be covered in next tutorial.

Changing color of hint of TextInputLayout

Open your Style.xml file resides in your “Resource” directory. Create a new style with custom name. I provided name="TextAppearence.TextInputLayout.Blue" here. Provide it parent theme as parent="@android:style/TextAppearance".

style has child tag called item. You can use this tag to customize parent style you have extended.

Add following line of code into style tag.

<item name="android:textColor">@color/make_me_blue</item>

After adding above line of code, your style tag will look like this. In this example, I add name="android:textSize" to provide size of hint to TextInputLayout.

Now, open your "activity_main.xml" layout file. You need to add namespace to provide hint color. Write following line of code in root layout to use custom attribute in our layout file.

Now your root layout will look like

That’s it. You are almost near to change color of your hint of TextInputLayout. Add below line of code inside android.support.design.widget.TextInputLayout

app:hintTextAppearance="@style/TextAppearence.TextInputLayout.Blue"

Your whole widget tag will look like,

I created some more styles and provided to TextInputLayout. You can customize it as per your requirement.

It is time to run our demo. Build and execute it in device.



The source code for this article is available here

Summary

In this article, we learned how to apply custom color to hint of TextInputLayout. You can apply any color to hint as per your need.

You may also like to read

TextInputLayout – Material Design Support li... This time in Google I/O 2015, it come up with Android M developers preview announcement and lots of other stubs which increase developers to be Materi...
ProGuard Secure your APK from Reverse Engineering ... Following are words from http://proguard.sourceforge.net who are inventor of it. ProGuard is a free Java class file shrinker, optimizer, obfuscator...
Develop apps faster using Data Binding – Par... Google has been pushing updates to existing tools and making the life of android developers easier. They also have been releasing new libraries and AP...
MaxHeightScrollView in Android using Android Studi... In Android, there are two constants for providing height and width of any view. But if you provide any specific height to any view, it won't be change...
Share on Facebook0Share on Google+2Tweet about this on TwitterShare on LinkedIn0Share on Reddit0Pin on Pinterest0Share on Tumblr0Email this to someone