Text fields according to Material design standards

Tram Ho

Text field helps users enter and edit text.

1. Using text field

Text fields are divided into 2 types:

  • Filled text fields
  • Outlined text fields.

Text field components:

Before you can use Material text fields, you need to add a dependency for the Material Components:

Check if Google’s Maven Repository google() is available:

Add library:

Once done, I will implement the Text field into the xml file:

A text field consists of a TextInputLayout and a TextInputEditText as a child.

Add a leading icon to the text field:

Add a trailing icon for the text field: Password touggle:

Clear text:

Add text helper for text field:

Add a counter text to the text field:

Add error text to the text field:

2. Filled text field

Here is a filled text field:

3. Outlined text fields

Here is a outlined text field:

4. Theming text fields

Here is an example of filled and oulined text fields using Material Theming:

Implement text filed theming:

Use theme attributes and styles in res/values/styles.xml:

Or use default style theme attributes, styles and theme overlays:

Or use a style in the layout:

Refer:: Material.io https://material.io/components/text-fields

Share the news now