Problem with previous libraries I found, for floating label, was that EditText was always incompletely overloaded. (EditText is a object with so many options)
With this method, a custom view simply wraps the EditText, leaving the dev to utilize a normal EditText's attributes.
I am going to try add some more features for the floating label custom view.
- Custom Attributes: Custom Attributes defined by library
- Original Attributes: Original Android Attributes
The Custom Attributes are equivalent to their Original Attribute versions
- flPadding
- flPaddingLeft (works as both PaddingLeft and PaddingStart)
- flPaddingRight (works as both PaddingRight and PaddingEnd)
- flPaddingTop
- flPaddingBottom
- flGapSize
- flAnimationDuration
- flGravity
- flText
- flScrollHorizontally
- flEllipsize
- flIncludeFontPadding
- flTextScaleX
-
flFontFamily
-
flTypeface
-
flTextStyle
-
flTextColor
-
flTextSize
-
flShadowColor
-
flShadowDx
-
flShadowDy
-
flShadowRadius
-
flTextAllCaps
-
flTextAppearance (Takes a reference to style. But the style can only have the equivalent Original Attributes of the attributes listed above (Under Text Apprearance)
<EditText
android:id="@+id/e3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Edit 3"/>
Notice how the style is defined with original attributes. Any custom attributes defined in the layout will overwrite the original style attribute. So the FloatLabel defined above will have a textSize of 16sp instead of the 8sp defined in the style.
- Padding
- flPaddingLeft
- flPaddingRight
Both these attributes will take into account the SDK version. If the SDK version is 17 above it will automatically use the flPaddingLeft
value as paddingStart
. Same for flPaddingRight
.
- Text Color
- flTextColor (or android:textColor in style)
In the absence of a color being defined, the follow color will be applied by default. (In the future, I am planing to make it default to accent color)
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- The color when activated/focused (usually your app's accent color) -->
<item android:color="@android:color/black" android:state_activated="true" />
<!-- The color when not activated/focused (usually grey) -->
<item android:color="@android:color/darker_gray" />
</selector>
- Single Line
The label by default is set as a single line.
Chris Banes' FloatLabelLayout(Gist) idea where custom view is simply a wrapper.