Skip to content
Carsten H edited this page Feb 27, 2015 · 24 revisions

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 Base/Primary/Error Color

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: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:primaryColor in xml or setPrimaryColor() in java code. If you haven't set a primary color, the base color will be used.

app:baseColor="#0056d3"
app:primaryColor="#982360"
app:errorColor="#ddaa00"

BaseColor

  1. Floating Label

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

normal:

app:floatingLabel="normal"

FloatingLabel

highlight:

app:floatingLabel="highlight"

HighlightFloatingLabel

custom floating label text:

app:floatingLabelText="XXX"

CustomFloatingLabelText

  1. Single Line Ellipsis

Use app: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:singleLineEllipsis is enabled.

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

app:singleLineEllipsis="true"

SingLineEllipsis

  1. Min and Max Characters

Use app: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:errorColor or setErrorColor() in java code.

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

app:minCharacters="5"
app:maxCharacters="10"

default error color:

MaxCharacters

  1. Helper Text and Error Text

HelperTextAndErrorText

helper text:

app: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:accentTypeface="fonts/Roboto-LightItalic.ttf"

CustomAccentTypeface

  1. Hide Underline
app: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+"));

AutoCompleteTextView support

Just use MaterialAutoCompleteTextView instead of MaterialEditText.

Clone this wiki locally