Giter VIP home page Giter VIP logo

materialedittext's Introduction

MaterialEditText

Android Arsenal

NOTE: 2.0 is NOT BACKWARDS COMPATIBLE! See more on wiki or 中文看这里

MaterialEditText

AppCompat v21 makes it easy to use Material Design EditText in our apps, but it's so limited. If you've tried that, you know what I mean. So I wrote MaterialEditText, the EditText in Material Design, with more features that Google Material Design Spec has introduced.

Features

  1. Basic

Basic

  1. Floating Label

normal:

FloatingLabel

highlight:

HighlightFloatingLabel

custom floating label text:

CustomFloatingLabelText

  1. Single Line Ellipsis

SingLineEllipsis

  1. Max/Min Characters

MaxCharacters

MinCharacters

MinAndMaxCharacters

  1. Helper Text and Error Text

HelperTextAndErrorText

  1. Custom Base/Primary/Error/HelperText Colors

CustomColors

  1. Custom accent typeface

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

CustomAccentTypeface

  1. Hide Underline

HideUnderLine

  1. Material Design Icon

MaterialDesignIcon

Sample

MaterialEditText-2.1.4-sample.apk

Download

Eclipse: MaterialEditText-2.1.4.aar

gradle:

compile 'com.rengwuxian.materialedittext:library:2.1.4'

Maven:

<dependency>
  <groupId>com.rengwuxian.materialedittext</groupId>
  <artifactId>library</artifactId>
  <version>2.1.4</version>
  <type>aar</type>
</dependency>

Usage

See on Wiki Page or 中文看这里

Thanks to

NineOldAndroids

License

Copyright 2014 rengwuxian

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

materialedittext's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

materialedittext's Issues

Visual consistency with Android 5 EditText

This is a great widget, but unfortunatelly it looks different then basic EditText in Android 5. I set baseColor to #000, but MaterialEditText line is gray and standard hint (when there is no text entered yet) is much brighter then in build-in EditText.

Currently we can't use standard EditText and MaterialEditText widgets in same app because of style consistency.

Can't get basic features to work

Hi!

First of all I would like to thank you for contributing to the Android community.

I just started using your library (version 1.6.0 via gradle) for my application and I can't seem to get basic features to work.

My xml:

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/tools"
    android:layout_height="match_parent"
    android:layout_width="match_parent"
    android:orientation="vertical"
    android:padding="16dp">

    <com.rengwuxian.materialedittext.MaterialEditText
        android:id="@+id/name_material_edit_text"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="@string/name"
        android:textCursorDrawable="@drawable/cursor_accent"
        app:baseColor="@android:color/black"
        app:floatingLabel="highlight"
        app:primaryColor="@color/accent" />

</LinearLayout>

Then I have a super simple activity which sets its content view to the xml above and does nothing more.

When I run the activity this is what I get:

  • an edit text, focused, with a hint "Name" with light gray. This is expected.
  • even though the edit text is focused, the horizontal line is black instead of using my accent color. This is not expected.
  • as I start typing, there is no floating label. This is not expected.

I have also tried setting an error by calling mEditText.setError("error text"); but that didn't display any error.

So basically, almost nothing is working for me :/

I am running 4.4.2 in a Nexus 5. I tried your sample apk and that seems to work just fine. I get all the nice features, like floating label, errors, colouring of horizontal line and so on.

Do you know what I might be doing wrong?

Thanks again!

android:inputType not working properly

Hi, first of all.. GOOD job with this library :-)

When using MaterialEditText if android:inputType="textPassword", chars doesn't change and password shows as plain text.
Any ideas on how to achieve the normal behaviour for inputType = password.

PS: other inputTypes like numberDecimal, textEmailAddress, number, etc are all working correctly

java.lang.IllegalArgumentException: Layout: -36 < 0

From one of my user who is using Micromax A110:
This is the error.

java.lang.IllegalArgumentException: Layout: -36 < 0
at android.text.Layout.(Layout.java:138)
at android.text.StaticLayout.(StaticLayout.java:104)
at android.text.StaticLayout.(StaticLayout.java:90)
at android.text.StaticLayout.(StaticLayout.java:68)
at android.text.StaticLayout.(StaticLayout.java:48)
at com.rengwuxian.materialedittext.MaterialEditText.adjustBottomLines(MaterialEditText.java:468)
at com.rengwuxian.materialedittext.MaterialEditText.setError(MaterialEditText.java:655)
at android.widget.TextView$1.run(TextView.java:3333)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:153)
at android.app.ActivityThread.main(ActivityThread.java:5086)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:821)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:584)
at dalvik.system.NativeStart.main(Native Method)

Hide Underline changes the size of the view

When modifying the hideUnderline property, the size of the view changes according to whether the underline is shown or not.

This is not ideal if the underline is being toggled programmatically, as it may affect the positioning of the text itself (if layout_gravity is anything other than top) or it may affect the placement of any views below it.

I think that hideUnderline should preserve the space where the underline should go, similarly to the way that View.INVISIBLE works as opposed to View.GONE within layouts.

Perhaps the View.INVISIBLE and View.GONE values could be used in order to support both variants.

Full-width text field

Any thoughts about implementing a full-width text field as could be seen in the guidelines? Do you think it could be easily added to the library?
Should it be a separate class maybe?

screenshot

Support for background attribute

Title kind of says it. It would be useful to be able to set a background color/resource/drawable, right now it seems the library just ignores these attributes (both in xml and programmatically). Particularly because sometimes you want to use a special 9-patch for the background

[Idea] Allow specified float label text, default to hint text

What would you think of this?

Specifically in the case where the hint is something longer, such as "Description (optional)". Having that as a label doesn't look very good. If no specific float label text is specified, then default back to the value of the hint text. I could pull request something like this if you'd be interested!

helperText measure fails on visibility:gone

When the visibility of the container for an MaterialEditText with helperText is set to gone, the helperText thinks it's width is zero and shows 1 character per line.

The workaround for this is to set the view's initial visibility to invisible instead of gone. It draws correctly, then all subsequent times the view is set to gone then back to visible again it works correctly. It just initially has to be set to invisible instead of gone.

Layout:
https://gist.github.com/robisaks/e9e035e3f8c63f0b4bb1

screenshot_2014-12-09-13-21-05

Ability to set floating text font

It would be nice if we could specify the font family used by the floating text. textAppearance works for the hint and regular text, but I cannot change the font of the floating text. Most of my UI uses roboto thin over roboto normal

Problem with Focus

Hello,

When you have a MaterialEditText in one activity, this MaterialEditText gets focus when this activity starts and then the keyboard appears. How can I clear this focus to let the user decide if he wants to edit this field or not by clicking on it.

TLDR : How remove the autofocus of MaterialEditText ?

Thanks !

Have a nice day.

Calling setError in own TextWatcher.onTextChanged has no effect

Hi!

I have a TextChangedListener in my MaterialEditText which, in function afterTextChanged, checks if the current text is correct based on some internal criteria. If it is not correct, it calls the function setError on the MaterialEditText:

mNameEditText.addTextChangedListener(new TextWatcher() {
      @Override public void beforeTextChanged(CharSequence s, int t, int c, int a) { }
      @Override public void afterTextChanged(Editable s) { }

      @Override
      public void onTextChanged(CharSequence s, int start, int before, int c) {
        if (true) {  // here I would put my error criteria
          mNameEditText.setError("foo error");
        }
      }
    });

This gives my users a better UX by letting them see immediately if what they just entered is correct or not. This mindset is encouraged in the Google Design guidelines:
"Don’t let them (your users) submit a long form before telling them they made an error. Disable a form submission button if errors are detected."

Unfortunately the code above doesn't work.

After reading a bit the code in MaterialEditText.java I get the impression that, as of now, it doesn't offer the possibility to set errors within afterTextChanged because of line 274 in MaterialEditText.java (https://github.com/rengwuxian/MaterialEditText/blob/master/library/src/main/java/com/rengwuxian/materialedittext/MaterialEditText.java#L274)

That line is setting the error to null every time the text changes, which seems to override the error I am setting from my afterTextChanged.

Is there any way that I can set an error in afterTextChanged?

Widget Margin

For some reason the top and bottom margins of the widget are not matching the screenshot you provided (much bigger in my tests). I don't know if this is how it should look like, but imho the margin amount should be decision of the designer/developer.

Tested in almost all supported API's with the same outcome.

Attaching a screenshot of your sample app, but this happened to me when I tried the widget in my own app too.

wrongmargin

Custom Design

When i disable a edittext it doesn't change so the user won't now it's disabled. Am i doing somting wrong or?

Code:
image
image
image
image

Option to disable transition animations

I love the way that the floating label animates into view, but I don't always want this in my application.

Is it possible to add a setting and styleable to enable/disable this feature? Default on would be ok.

Option to make MaterialEditText non editable

Hi there,

Thanks for the lib. It will be really helpful to add a method to make the edit text non editable if desired. I guess some people will need it the same as I do. I could make PR in case you need it.

Thanks once again.

font size problem

Hey. Is it possible to have two diferent font sizes for the value and the hint? I can change the value font size but the hint is too small sometimes, and i find no information in the wiki on how to change only the hint font sixr. Is there any option?

RTL Support

Have you looked into RTL support much? The EditText field itself supports it, but the accent texts still draw from left to right when it's enabled

Auto validation does not call Validator

Enabling auto validation with either setAutoValidate(true) or autoValidate="true" does not seem to trigger Validator execution while typing or changing focus.

Set focusable, focusableInTouchMode and clickable attributes to false in XML

This is related to closed issue #44.

I'd like to set the focusable, focusableInTouchMode and clickable attributes to false in XML.

Unfortunately, I can't do so as the MaterialEditText constructor forces these to true after calling super.

Could these be removed or worked around somehow in order to provide the ability to set these properties in XML?

"Rendering problems" in Android Studio preview window

Hi!

First of all, thanks for an amazingly useful library.

I'm facing the following issue when opening layouts containing MaterialEditText in the Android Studio Preview:

Rendering Problems The following classes could not be instantiated:
- com.rengwuxian.materialedittext.MaterialEditText (Open Class, Show Exception)
Tip: Use View.isInEditMode() in your custom views to skip code or show sample data when shown in the IDE

Here's the stack trace of the exception:

java.lang.AssertionError
    at android.content.res.BridgeResources.getDimensionPixelSize(BridgeResources.java:397)
    at com.rengwuxian.materialedittext.MaterialEditText.<init>(MaterialEditText.java:159)
    at com.rengwuxian.materialedittext.MaterialEditText.<init>(MaterialEditText.java:149)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
    at org.jetbrains.android.uipreview.ViewLoader.createNewInstance(ViewLoader.java:379)
    at org.jetbrains.android.uipreview.ViewLoader.loadView(ViewLoader.java:99)
    at com.android.tools.idea.rendering.LayoutlibCallback.loadView(LayoutlibCallback.java:172)
    at android.view.BridgeInflater.loadCustomView(BridgeInflater.java:207)
    at android.view.BridgeInflater.createViewFromTag(BridgeInflater.java:132)
    at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:806)
    at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:64)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:782)
    at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:809)
    at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:64)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:782)
    at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:809)
    at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:64)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:782)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:385)
    at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:401)
    at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:329)
    at com.android.ide.common.rendering.LayoutLibrary.createSession(LayoutLibrary.java:350)
    at com.android.tools.idea.rendering.RenderService$5.compute(RenderService.java:688)
    at com.android.tools.idea.rendering.RenderService$5.compute(RenderService.java:677)
    at com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:932)
    at com.android.tools.idea.rendering.RenderService.createRenderSession(RenderService.java:677)
    at com.android.tools.idea.rendering.RenderService.render(RenderService.java:815)
    at org.jetbrains.android.uipreview.AndroidLayoutPreviewToolWindowManager.doRender(AndroidLayoutPreviewToolWindowManager.java:611)
    at org.jetbrains.android.uipreview.AndroidLayoutPreviewToolWindowManager.access$1900(AndroidLayoutPreviewToolWindowManager.java:81)
    at org.jetbrains.android.uipreview.AndroidLayoutPreviewToolWindowManager$7$1.run(AndroidLayoutPreviewToolWindowManager.java:553)
    at com.intellij.openapi.progress.impl.ProgressManagerImpl$2.run(ProgressManagerImpl.java:178)
    at com.intellij.openapi.progress.ProgressManager.executeProcessUnderProgress(ProgressManager.java:209)
    at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:212)
    at com.intellij.openapi.progress.impl.ProgressManagerImpl.runProcess(ProgressManagerImpl.java:171)
    at org.jetbrains.android.uipreview.AndroidLayoutPreviewToolWindowManager$7.run(AndroidLayoutPreviewToolWindowManager.java:548)
    at com.intellij.util.ui.update.MergingUpdateQueue.execute(MergingUpdateQueue.java:320)
    at com.intellij.util.ui.update.MergingUpdateQueue.execute(MergingUpdateQueue.java:310)
    at com.intellij.util.ui.update.MergingUpdateQueue$2.run(MergingUpdateQueue.java:254)
    at com.intellij.util.ui.update.MergingUpdateQueue.flush(MergingUpdateQueue.java:269)
    at com.intellij.util.ui.update.MergingUpdateQueue.flush(MergingUpdateQueue.java:227)
    at com.intellij.util.ui.update.MergingUpdateQueue.run(MergingUpdateQueue.java:217)
    at com.intellij.util.concurrency.QueueProcessor.runSafely(QueueProcessor.java:238)
    at com.intellij.util.Alarm$Request$1.run(Alarm.java:327)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:439)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
    at java.util.concurrent.FutureTask.run(FutureTask.java:138)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
    at java.lang.Thread.run(Thread.java:695)

Option to hide underline

What would you think of this? This is usually accomplished in a regular EditText by setting the background to transparent or an invisible custom drawable. Setting primary/base color to transparent somewhat accomplishes this, but still leaves it off-center and also forfeits the use of those colors for any other paints.

primaryColor

Custom primaryColor not working on 1.4.0 lib also in your demo app not working too.

Add programmatic setter access to icons

Icons can only be set in the XML view and imply that there's an actual bitmap resource.

I'm using the excellent android-material-icons library, which generates the bitmaps from a vector font, allowing indefinite, crisp resizing and avoids having to generate 5 images for every icon.

Programmatically, I can pull out a Drawable in any size and color, but I can't seem to apply it on MaterialEditText. A setter would be very much appreciated.

Floating label gravity

If you change the gravity of the EditText, for example gravity="center_horizontal", you can have the text centered horizontally, but with the floating label left aligned. Not really sure if it's by design or a bug.

Having the floating label with the same gravity as the text might be prettier.

Horizonal line color when EditText not focused

Hi again and sorry for spamming you with questions that I end up fixing myself.

This one I don't think I will answer myself though :)

I got everything to work great with your library except one little detail! And that is the color of the horizontal line when the the EditText is not focused.

As far as I can see, the BaseColor sets the font color and the color of the horizontal line when unfocused. But the thing is, according to material design guidelines, those two should be different:

https://www.google.com/design/spec/components/text-fields.html#text-fields-single-line-text-field

Take a look at those fields that have information in them but are not focused. The font is black, but the horizontal line is a very light gray.

I can't seem to achieve this with your library. Is it possible?

Many thanks!

bug: multiline

I set android:lines="4". If there are 5 lines in the MaterialEditText, the underline will be scrolled when you scroll the MaterialEditText.

我设置了 android:lines="4"
当输入框内文本大于4行的时候,如果滚动MaterialEditText,底部的那条线会一起滚动

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.