Skip to content
Kamran Ahmed Ansari edited this page May 15, 2015 · 24 revisions

NOTE: 2.0 is NOT BACKWARDS COMPATIBLE. If you're already using 1.x of MaterialEditText, better to see the differences:

  • To avoid conflicts with stock/third party libraries, v2.0 give every attribute a prefix met_.
  • New rule of baseColor's default value. Old default value: fetch the window's background color and calculate a contrasting color (black or white). New default value: always black.

Features and Usage

  1. Basic

Just use com.rengwuxian.materialedittext.MaterialEditText instead of EditText in your layout xml. MaterialEditText has directly inherited EditText, so you don't have to change your java code.

<com.rengwuxian.materialedittext.MaterialEditText
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:hint="Basic"/>

Basic

  1. Custom Colors

Base color will be used as bottom line color, text color (reset alpha to 87%) and hint text color (reset alpha to 26%). You can use app:met_baseColor in xml or setBaseColor() in java code. If you haven't set a base color, black will be used.

Primary color will be used as the activated bottom line color, highlight floating label color, and singleline ellipsis color. You can use app:met_primaryColor in xml or setPrimaryColor() in java code. If you haven't set a primary color, the base color will be used.

You can also customize other colors, such as floating label color, helper text color, error color, underline color, etc. It's important to note that you should use met_textColor and met_textColorHint instead of the built-in android:textColor and android:textColorHint, if you want to custom the main text's or the hint text's color.

app:met_baseColor="#0056d3"
app:met_primaryColor="#982360"
app:met_errorColor="#ddaa00"

BaseColor

  1. Floating Label

There're 3 modes of floating label: none, normal, and highlight. You can use app:met_floatingLabel in xml or setFloatingLabel() in java code.

normal:

app:met_floatingLabel="normal"

FloatingLabel

highlight:

app:met_floatingLabel="highlight"

HighlightFloatingLabel

custom floating label text:

app:met_floatingLabelText="XXX"

CustomFloatingLabelText

  1. Single Line Ellipsis

Use app:met_singleLineEllipsis=true int xml or setSingleLineEllipsis() in java code to enable the ellipsis for when some texts scroll left. Touching the ellipsis jumps the cursor back to the beginning of the string. android:singleLine will be set true automatically when app:met_singleLineEllipsis is enabled.

NOTE: Single Line Ellipsis may increase the View's height to the bottom.

app:met_singleLineEllipsis="true"

SingLineEllipsis

  1. Min and Max Characters

Use app:met_maxCharacters in xml or setMaxCharacters() in java code to set the max characters count. The bottom line will turn red when exceeding max characters. 0, as default, means no max characters. You can also customize the error color using app:met_errorColor or setErrorColor() in java code.

NOTE: Min/Max Characters may increase the View's height to the bottom.

app:met_minCharacters="5"
app:met_maxCharacters="10"

default error color:

MaxCharacters

  1. Helper Text and Error Text

HelperTextAndErrorText

helper text:

app:met_helperText="Integer"

error text:

just use original setError(CharSequence error) in java code.

regex check:

validationEditText.isValid("\\d+");

regex validate with error text setting:

validationEditText.validate("\\d+", "Only Integer Valid!");
  1. Custom accent typeface

floating label, error/helper text, character counter, etc.

app:met_accentTypeface="fonts/Roboto-LightItalic.ttf"

CustomAccentTypeface

  1. Hide Underline
app:met_hideUnderline="true"

HideUnderLine

  1. Validation

This will automatically show the error text.

One-off validation:

et.validateWith(new RegexpValidator("Only Integer Valid!", "\\d+"));

Complex:

et.addValidator(new CustomValidator1())
  .addValidator(new CustomValidator2())
  .addValidator(new RegexpValidator("Only Integer Valid!", "\\d+"));

All attributes

General colors

met_baseColor: The base color of the line and all the texts in non-focus state. Black as default.

met_primaryColor: The highlight color of the line, and the floating label (if the met_floatingLabel is set to true). Using baseColor as default.

met_textColor: Same meaning as android:textColor. Just use this instead.

met_textColorHint: Same meaning as android:textColorHint. Just use this instead.

met_underlineColor: Custom underline's color.

Floating label

met_floatingLabel: How the floating label should be shown. Options: none, normal, highlight. None as default.

met_floatingLabelText: Custom float label text.

met_floatingLabelTextSize: The floating label's text size. 12sp by default.

met_floatingLabelTextColor: The floating label's text color. Using translucent baseColor by default.

met_floatingLabelPadding: Padding between the main text and the floating label.

met_floatingLabelAnimating: Whether use animation to show/hide the floating label. True by default.

met_floatingLabelAlwaysShown: Always show the floating label, instead of animating it in/out. False as default.

Characters counter

met_minCharacters: Min characters count limit. 0 as default.

met_maxCharacters: Max Characters count limit. 0 means no limit. 0 as default.

Helper/Error text

met_helperText: Helper text at the bottom.

met_helperTextAlwaysShown: Always show the helper text, no matter if the edit text is focused. False as default.

met_helperTextColor: Helper text color.

met_errorColor: Error text's color.

met_bottomTextSize: The bottom texts(helper/error text)' size. 12sp by default.

met_minBottomTextLines: Reserved bottom text lines count, no matter if there is some helper/error text.

Typeface

met_typeface: Font used for the main texts.

met_accentTypeface: Font used for the accent texts.

Material Design icon

met_iconLeft: Left Material Design icon.

met_iconRight: Right Material Design icon.

met_iconPadding: Padding between the icon(s) and the main area. 16dp by default, following Google's Material Design Spec.

Others

met_hideUnderline: If the underline should be hidden. False as default.

met_autoValidate: Auto validate. False as default.

met_singleLineEllipsis: Whether to show the bottom ellipsis in singleLine mode. False as default.

met_clearButton: Whether to show the clear button. False as default.

AutoCompleteTextView support

Just use MaterialAutoCompleteTextView instead of MaterialEditText.

MultiAutoCompleteTextView support

Just use MaterialMultiAutoCompleteTextView instead of MaterialEditText.