Skip to content

privatmamtora/Android-FloatingLabel

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Android-FloatingLabel

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.

Definitions

  1. Custom Attributes: Custom Attributes defined by library
  2. Original Attributes: Original Android Attributes

Available 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

Text Appearance Attributes

  • 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)

Example

**Layout** ```XML
<EditText
    android:id="@+id/e3"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:hint="Edit 3"/>
``` **Style.xml** ```XML <style name="FloatLabel" parent="@android:style/TextAppearance.Small"> @color/floatlabel_text 8sp bold serif @color/floatlabel_shadow 5 5 15 </style> ```

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.

Non-Default Behavior

  1. 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.

  1. 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>
  1. Single Line

The label by default is set as a single line.

Original Concept

Chris Banes' FloatLabelLayout(Gist) idea where custom view is simply a wrapper.

About

An easier, more complete, Floating Label library

Resources

License

Stars

Watchers

Forks

Packages

No packages published