A Material Android password view that toggles password visibility via an eye icon.

Overview

8/17/2016: As of about an hour ago, this library is deprecated!

Support for password visibility is now included in the Design Support Library in TextInputLayout. 🎉

PasswordView [deprecated]

👀 "All eyes, yeah I see 'em" — Yo Gotti, Down in the DM

compile 'com.xwray:passwordview:1.0'

Drop-in Android password view for the new material design spec

<com.xwray.passwordview.PasswordView
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:hint="@string/password_hint" />

Toggle password visibility

Touch the "eye" icon to toggle between traditional and visible password states.

Custom typeface support

In the spec, the password field is pictured in Roboto. I really liked how this looked, so, I made PasswordView support custom typefaces! If you set one, it will stay. If you don't, the default is still monospace — no worries.

passwordView.setTypeface(roboto);

Optional strikethrough

By default, PasswordView adheres exactly to the spec, using 54% / 38% opacity for the visibility icon (or 50% / 100% for light on dark themes). The visibility icon is drawn using textColorPrimary and its opacity values (dark or light) are determined dynamically.

If you find opacity too subtle (insert eye roll 👀 ), you can use the visibility icon with a strikethrough instead. (idea credit, @thekeeperofpie)

app:useStrikeThrough="true" / passwordView.setUseStrikethrough(true)

Comments
  • Tint drawable based on PasswordView theme

    Tint drawable based on PasswordView theme

    Material Design specs did not specify what the 'eye' color should be when its dark theme. Resolving it to ?android:textColorPrimary


    This change is Reviewable

    opened by andhie 5
  • Using setError invalidates the eye toggle

    Using setError invalidates the eye toggle

    When using setError on the EditText the eye toggle stops working and does not toggle the drawable itself (the shown/hidden text works). I assume it resets the drawable somehow, any idea how to fix it?

    bug 
    opened by powder366 5
  • Vector Drawables Pre-Lollipop

    Vector Drawables Pre-Lollipop

    So I always thought that Vector Drawables were only supported on API 21+. But, I cloned your repo and ran your app on a API 19 device and the Vector Drawable rendered perfectly fine. Is there some reason why this all works on pre-lollipop? I was hoping you could explain.

    Also in your PasswordView.java class, on lines 67 and 68 you have

    eye = ContextCompat.getDrawable(getContext(), R.drawable.ic_eye).mutate();
    eyeWithStrike = ContextCompat.getDrawable(getContext(), R.drawable.ic_eye_strike).mutate();
    

    Shouldn't that be replaced with

    eye = VectorDrawableCompat.create(getResources(), R.drawable.ic_eye, null).mutate();
    eyeWithStrike = VectorDrawableCompat.create(getResources(), R.drawable.ic_eye_strike, null).mutate();
    

    to support vector drawables on all API versions?

    opened by lawloretienne 4
  • Fix click event bug

    Fix click event bug

    Fix clicked coordinate calculation bug,handle the click event correctly Considering more about padding and PasswordView don't start from the left of parent view~ 修复点击坐标的计算,能正确响应点击事件

    opened by nickwongwong 3
  • clicked coordinate calculation error of eye icon

    clicked coordinate calculation error of eye icon

    When we use "padding" or "center_horizontal" of PasswordView, (getRight() - getCompoundDrawables()[2].getBounds().width()) will not show the true location of eye icon. In this way, onTouchEvent can not handle the click event correctly. Using getWidth() instead of getRight(), and getPaddingRight()

    bug 
    opened by nickwongwong 2
  • The non highlighted underline remains visible when PasswordView is highlighted.

    The non highlighted underline remains visible when PasswordView is highlighted.

    First of all, nice library. I just noticed one little thing. The non highlighted underline remains visible when PasswordView is highlighted. Device: Samsung Galaxy S4, Android 5.0.1. Hope it helps. device-2016-03-16-153619 device-2016-03-16-153631

    opened by jpardogo 2
  • Extend AppCompatEditText instead of EditText

    Extend AppCompatEditText instead of EditText

    Since this library targets 14 as its minimum, it would be great if it would add a dependency on AppCompat and extend AppCompatEditText instead so that the material edit text style would apply even on pre 21 devices.

    opened by Jawnnypoo 1
  • Can you add a CHANGELOG

    Can you add a CHANGELOG

    🎆 🎆 🎆 🎆 🎆 🎆 Congrats on v 1.0 !!

    Can you add a changel og for future changes? That'll make it easy to scan for change instead of parsing commit history?

    opened by tir38 0
  • Add appropriate alpha for dark/light themes

    Add appropriate alpha for dark/light themes

    Toggle color is based on textColorPrimary (colorControlNormal has its opacity adjusted). Alpha adjustment is done with manual calculation in the view. Would be nice to just read these values from somewhere.

    Adds day / night theme toggle in demo activity.

    opened by lisawray 0
  • Support other password input types

    Support other password input types

    TextView has a much more sophisticated concept of what's "password" and what's "visibile" https://android.googlesource.com/platform/frameworks/base/+/refs/heads/master/core/java/android/widget/TextView.java#4581

    opened by lisawray 0
  • Preserve selection state when password visibility is toggled

    Preserve selection state when password visibility is toggled

    There were two problems here:

    • Setting the input type resets the selection indices. We have to preserve and re-set them ourself.
    • Letting the TextView respond itself to clicks on MotionEvent.DOWN on the eye meant it was registering a click on the text field, which moved the cursor to the end. We probably need more sophisticated touch handling on the eye in general.
    opened by lisawray 0
  • Application crashes if password field is blank with validation too

    Application crashes if password field is blank with validation too

    So i recently used this library, i basically want to add a checkpoint to my application where if user leave password empty the application sets error to the field, i used password view for password field. But when user continues without entering password the application crashes, no matter if he enters email only too, i already have check point of seterror added on the email field my email field is a simple edit text and password field is password view,i tried checking logcat and it says "Please use TextInputLayout.setError() instead! at com.xwray.passwordview.PasswordView.setError", i tried setting the type to textinputlayout but it throws an error of casting i.e. "Unable to cast edittext on textinputlayout", below is the xml and java code of my application

    image_2022-03-11_113339 image image

    image of exception image

    opened by junaidraz1 0
  • De-deprecating this library ?

    De-deprecating this library ?

    Hi,

    When i wanted to implement this library to another new project , i just see that this library was deprecated because the password view has been integrated in the support library, i tested it but i think it's too much complex, we need a layout wrapper and a control inside. This support layout is great when we wan't a material design app with the text going to the top, but in my new project, i need to use a custom design and a custom font and this library is just what i need, i can subclass it to use my custom font. And this library is very easy to implement just replace EditText with it.

    So for some uses, this library is very great and easier than the support library, so i think it should not be deprecated.

    opened by alvinmeimoun 1
  • PasswordView cannot be shown in the Android Studio Preview window

    PasswordView cannot be shown in the Android Studio Preview window

    The stacktrace is the following:

    java.lang.NoSuchMethodError: android.graphics.drawable.VectorDrawable_Delegate.nCreateTreeFromCopy(JJ)J
        at android.graphics.drawable.VectorDrawable.nCreateTreeFromCopy(VectorDrawable.java)
        at android.graphics.drawable.VectorDrawable.access$400(VectorDrawable.java:204)
        at android.graphics.drawable.VectorDrawable$VectorDrawableState.createNativeTreeFromCopy(VectorDrawable.java:837)
        at android.graphics.drawable.VectorDrawable$VectorDrawableState.<init>(VectorDrawable.java:812)
        at android.graphics.drawable.VectorDrawable.mutate(VectorDrawable.java:268)
        at com.xwray.passwordview.PasswordView.getToggleDrawable(PasswordView.java:90)
        at com.xwray.passwordview.PasswordView.init(PasswordView.java:75)
        at com.xwray.passwordview.PasswordView.<init>(PasswordView.java:49)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
        at org.jetbrains.android.uipreview.ViewLoader.createNewInstance(ViewLoader.java:465)
        at org.jetbrains.android.uipreview.ViewLoader.loadClass(ViewLoader.java:172)
        at org.jetbrains.android.uipreview.ViewLoader.loadView(ViewLoader.java:105)
        at com.android.tools.idea.rendering.LayoutlibCallbackImpl.loadView(LayoutlibCallbackImpl.java:176)
        at android.view.BridgeInflater.loadCustomView(BridgeInflater.java:247)
        at android.view.BridgeInflater.createViewFromTag(BridgeInflater.java:171)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727)
        at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:858)
        at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:70)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:834)
        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821)
        at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:861)
        at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:70)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:834)
        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821)
        at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:861)
        at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:70)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:834)
        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821)
        at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:861)
        at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:70)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:834)
        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821)
        at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:861)
        at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:70)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:834)
        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:518)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
        at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:317)
        at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:429)
        at com.android.ide.common.rendering.LayoutLibrary.createSession(LayoutLibrary.java:350)
        at com.android.tools.idea.rendering.RenderTask$2.compute(RenderTask.java:520)
        at com.android.tools.idea.rendering.RenderTask$2.compute(RenderTask.java:508)
        at com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:967)
        at com.android.tools.idea.rendering.RenderTask.createRenderSession(RenderTask.java:508)
        at com.android.tools.idea.rendering.RenderTask.access$600(RenderTask.java:75)
        at com.android.tools.idea.rendering.RenderTask$3.call(RenderTask.java:620)
        at com.android.tools.idea.rendering.RenderTask$3.call(RenderTask.java:617)
        at com.android.tools.idea.rendering.RenderService.runRenderAction(RenderService.java:371)
        at com.android.tools.idea.rendering.RenderTask.render(RenderTask.java:617)
        at com.android.tools.idea.rendering.RenderTask.render(RenderTask.java:639)
        at org.jetbrains.android.uipreview.AndroidLayoutPreviewToolWindowManager.doRender(AndroidLayoutPreviewToolWindowManager.java:654)
        at org.jetbrains.android.uipreview.AndroidLayoutPreviewToolWindowManager.access$1700(AndroidLayoutPreviewToolWindowManager.java:82)
        at org.jetbrains.android.uipreview.AndroidLayoutPreviewToolWindowManager$7$1.run(AndroidLayoutPreviewToolWindowManager.java:596)
        at com.intellij.openapi.progress.impl.CoreProgressManager$2.run(CoreProgressManager.java:142)
        at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:446)
        at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:392)
        at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:54)
        at com.intellij.openapi.progress.impl.CoreProgressManager.runProcess(CoreProgressManager.java:127)
        at org.jetbrains.android.uipreview.AndroidLayoutPreviewToolWindowManager$7.run(AndroidLayoutPreviewToolWindowManager.java:591)
        at com.intellij.util.ui.update.MergingUpdateQueue.execute(MergingUpdateQueue.java:337)
        at com.intellij.util.ui.update.MergingUpdateQueue.execute(MergingUpdateQueue.java:327)
        at com.intellij.util.ui.update.MergingUpdateQueue$3.run(MergingUpdateQueue.java:271)
        at com.intellij.util.ui.update.MergingUpdateQueue.flush(MergingUpdateQueue.java:286)
        at com.intellij.util.ui.update.MergingUpdateQueue.flush(MergingUpdateQueue.java:244)
        at com.intellij.util.ui.update.MergingUpdateQueue.run(MergingUpdateQueue.java:234)
        at com.intellij.util.concurrency.QueueProcessor.runSafely(QueueProcessor.java:238)
        at com.intellij.util.Alarm$Request$1.run(Alarm.java:352)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        at java.lang.Thread.run(Thread.java:745)
    
    opened by bryant1410 1
  • Option to disable vibration when visibility is toggled

    Option to disable vibration when visibility is toggled

    It appears that the device does a short vibration when the visibility is changed (and the cursor jumps to the end).

    Can we get an option to disable this "feature"? It seems handy to indicate that a password-field got visible but it would be good to decide ourselves.

    PS: Why is it vibrating in the first place? I cannot identify the piece of code doing it. PPS: Using Android N Preview 2

    opened by hardysim 3
Owner
Lisa Wray
Lisa Wray
Android Custom View for prevent the view behind on-screen keyboard when edit text is focused

Group Focusable Prevent the view behind on-screen keyboard when edit text is focused in Android UI Download Gradle implementation 'com.akexorcist:grou

Akexorcist 8 Jun 22, 2022
Custom view to expand long text with view more,less action , you can customize min lines , action color

ExpandableTextView Custom expadable text view Examples : <mostafa.projects.expandabletextview.ExpandableTextView android:layout_wi

Mostafa Gad 8 Jan 25, 2022
A material style input for codes

Material Code input A material style input for put codes Based on Code input field concept by SAMUEL KANTALA How to use Minimal SDK Version 11 Usage w

Adrián Lomas 962 Nov 26, 2022
Android Bubble View

BubbleTextView Custom arrow position Custom fillet radius Custom background color Can be placed anywhere Two default style Two default theme Snapshot

null 669 Nov 11, 2022
RTL marquee text view android right to left moving text - persian - farsi - arabic - urdo

RTL marquee text view android right to left moving text - persian - farsi - arabic - urdo

mehran elyasi 4 Feb 14, 2022
Light-weighted, convenient implementation of expandable text view that supports expanding & collapsing animations for Android projects

ExpandableTextView Light-weighted, convenient implementation of expandable text view that supports expanding & collapsing animations for Android proje

Giang H. Pham 22 Jan 6, 2023
Provides a set of views which allows to adjust the spacing between the characters of that view, AKA, Kerning effect.

KerningViews KerningViews provides a set of views (currently only TextView and Button) which lets you adjust the spacing between the characters in the

Aritra Roy 148 Aug 7, 2022
Library project with a custom view that implements the Float Label pattern

AndroidFloatLabel This repository contains an Android library project for Android 4.0+ with a custom view that implements the Float Label pattern (htt

Ian G. Clifton 475 Dec 27, 2022
RichEditor for Android is a beautiful Rich Text WYSIWYG Editor for Android.

RichEditor for Android is a beautiful Rich Text WYSIWYG Editor for Android. Looking for iOS? Check out cjwirth/RichEditorView Supported Functions Bold

Daichi Furiya 6k Jan 2, 2023
MarkdownView is an Android webview with the capablity of loading Markdown text or file and display it as HTML, it uses MarkdownJ and extends Android webview.

MarkdownView is an Android webview with the capablity of loading Markdown text or file and display it as HTML, it uses MarkdownJ and extends Android webview.

Feras Alnatsheh 1k Dec 20, 2022
Android's TextView that can expand/collapse like the Google Play's app description

ExpandableTextView ExpandableTextView is an Android library that allows developers to easily create an TextView which can expand/collapse just like th

Manabu S. 4k Dec 28, 2022
A library to show emoji in TextView, EditText (like WhatsApp) for Android

Discontinued This projected is discontinued. Please consider using other alternative, i.e EmojiCompat. Contact me if you want to continue working on a

Hieu Rocker 3.6k Jan 5, 2023
Android experiment showing a sinking TextView

Titanic is an Android experiment reproducing this effect.

Romain Piel 1.8k Dec 15, 2022
:page_facing_up: Android Text Full Jusiftication / Wrapping / Justify / Hyphenate - V2.0

LIBRARY IS NO LONGER MAINTAINED If you want to adopt + maintain this library, please drop me a message - [email protected] Android Full Justific

Mathew Kurian 1.9k Dec 29, 2022
Android form edit text is an extension of EditText that brings data validation facilities to the edittext.

Android Form EditText Android form edit text is an extension of EditText that brings data validation facilities to the edittext. Example App I built a

Andrea 1.5k Dec 14, 2022
Gmail style MultiAutoCompleteTextView for Android

Version 3.0 The 3.0.1 version is now available! This should resolve a number of text handling issues and lay the groundwork for better support of mixe

Splitwise 1.3k Nov 14, 2022
Advanced Android TextView

Advanced Android TextView Companion app for my Advanced Android TextView talk, demostrating: Animated CompoundDrawable Text shadow Custom font Non-bre

Chiu-Ki Chan 1.2k Dec 9, 2022
[DISCONTINUED] Rrich text editor for android platform. 安卓富文本编辑器,暂停维护

icarus-android Maybe the best rich text editor on android platform. Base on Simditor Features Alignment (left/center/right) Bold Blockquote Code Horiz

Dyson Woo 739 Sep 5, 2022
RoundedLetterView like the one in Android 5.0 Contacts app

RoundedLetterView RoundedLetterView like the one in Android 5.0 Contacts app Attributes to choose from: rlv_titleText - The text in the first row. rlv

Pavlos-Petros Tournaris 651 Dec 30, 2022