With the advent of material design, appcompat V21 also provides visual support for material design controls, including edittext. However, edittext in appcompat is a bit difficult to use, because it uses col1_cent to automatically color the control and does not provide an API to set the color, therefore, you need to customize the color of the control by customizing theme for the control. Besides appearance changes, appcompat does not provide any features mentioned in Google material design spec. So I made this library: materialedittext. (In fact, a simple version has been ready for use some time ago, and the control will be re-built only after Google releases the new SDK and finds that the new SDK does not provide the expected support, made into the current version)
Features and usage:
Replace edittext with COM. rengwuxian. materialedittext. materialedittext in the layout file. Materialedittext is the directly inherited edittext without adding wrapper layout. Therefore, you do not need to modify the Java file in most cases.
<com.rengwuxian.materialedittext.MaterialEditText android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="Basic"/>
Base color is used as the color of the background line, the color of the main font (transparency is reset to 87%), and the color of the prompt font (transparency is reset to 26% ). You can useapp:baseColor
(XML) orsetBaseColor()
(Java) to specify the base color. The default value of base color is pure black.
app:baseColor="#0056d3"
Primary color is used as the background color, highlighted floating label color, and ellipsis at the bottom of the input box for activation. You can useapp:primaryColor
(XML) orsetPrimaryColor()
(Java) to specify the primary color. If primary color is not set, base color is used by default.
app:baseColor="#0056d3"app:primaryColor="#982360"
Floating label has three modes:none
,normal
,highlight
. You can useapp:floatingLabel
(XML) orsetFloatingLabel()
(Java) to set the floating label mode.
Normal:
app:floatingLabel="normal"
Highlight:
app:floatingLabel="highlight"
When the lower ellipsis is displayed, the control displays the ellipsis of three vertices on the left side of the text scroll to the left. Click the ellipsis to automatically place the cursor at the beginning of the string. You can useapp:singleLineEllipsis=true
(XML) orsetSingleLineEllipsis()
(Java) to set it. This property will be automatically setandroid:singleLine
True.
Note: The ellipsis at the bottom automatically increases the height at the bottom of the control.
app:singleLineEllipsis="true"
After setting the Character Count limit, the lower-right corner of the control displays the badge of the number of entered characters and the maximum number of characters, and the warning color (Red by default) is displayed after the limit is exceeded ). You can useapp:maxCharacters
(XML) orsetMaxCharacters()
(Java) to set the number of characters, throughapp:errorColor
OrsetErrorColor()
(Java) customize the warning color.
Note: The character number badge automatically increases the height at the bottom of the control.
Default error color:
app:maxCharacters="10"
Custom error color:
app:maxCharacters="10" app:errorColor="#ddaa00"
GitHub address: materialedittext
Library download: MaterialEditText-1.0.0.aar
Sample download: MaterialEditText-1.0.0-sample.apk
This article is sent to my personal blog and open source China.
[Materialedittext] edittext of material design