标签:需求 bre 下载地址 styleable toggle listener 抽象 width var
仿支付宝/微信的password输入框效果GridPasswordView解析,把一些设置和一些关键的地方列了出来,方便大家使用,可能能够省一部分的时间,也算是自己的积累吧。
1.password框能够输入的类型PasswordType
public enum PasswordType { NUMBER, TEXT, TEXTVISIBLE, TEXTWEB; }
@Override public void setPasswordType(PasswordType passwordType) { boolean visible = getPassWordVisibility(); int inputType = InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_VARIATION_PASSWORD; switch (passwordType) { case TEXT: inputType = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD; break; case TEXTVISIBLE: inputType = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD; break; case TEXTWEB: inputType = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_WEB_PASSWORD; break; } for (TextView textView : viewArr) textView.setInputType(inputType); setPasswordVisibility(visible); }
2.PasswordView中的抽象方法的作用
interface PasswordView { //获取password String getPassWord(); //清空password void clearPassword(); //设置password void setPassword(String password); //设置password可见性 void setPasswordVisibility(boolean visible); //password可见性的切换 void togglePasswordVisibility(); //设置password改变监听 void setOnPasswordChangedListener(GridPasswordView.OnPasswordChangedListener listener); //设置password类型 void setPasswordType(PasswordType passwordType); }
setBackground(Drawable) setBackgroundColor(int) setBackgroundResource(int) setBackgroundDrawable(Drawable)这个类是View的主类。能够通过这个类去满足你的需求
4.在GridPasswordView中设置框框颜色和背景颜色(绿色和红色)
private static final int DEFAULT_LINECOLOR = 0xaa61cea8; private static final int DEFAULT_GRIDCOLOR = 0xffe66961;
5.设置文本的大小和颜色(40px和蓝色)
private static final int DEFAULT_TEXTSIZE = 40; textColor = ColorStateList.valueOf(getResources().getColor(android.R.color.holo_blue_light));
<style name="GridPasswordView.TextView"> <item name="android:layout_width">0dp</item> <item name="android:layout_height">match_parent</item> <item name="android:background">@null</item> <item name="android:gravity">center</item> <item name="android:layout_weight">1</item> <item name="android:singleLine">true</item> </style> <style name="GridPasswordView.EditText" parent="GridPasswordView.TextView"> <item name="android:cursorVisible">false</item> </style> <style name="GridPasswordView.Divider"> <item name="android:layout_width">1dp</item> <item name="android:layout_height">match_parent</item> <item name="android:layout_marginTop">1dp</item> <item name="android:layout_marginBottom">1dp</item> </style>
<declare-styleable name="gridPasswordView"> <attr name="textColor" format="color|reference" /> <attr name="textSize" format="dimension" /> <attr name="lineColor" format="color" /> <attr name="gridColor" format="color" /> <attr name="lineWidth" format="dimension" /> <attr name="passwordLength" format="integer" /> <attr name="passwordTransformation" format="string" /> <attr name="passwordType" format="enum"> <enum name="numberPassword" value="0" /> <enum name="textPassword" value="1" /> <enum name="textVisiblePassword" value="2" /> <enum name="textWebPassword" value="3" /> </attr> </declare-styleable>
8.效果图
仿支付宝/微信的password输入框效果GridPasswordView解析
标签:需求 bre 下载地址 styleable toggle listener 抽象 width var
原文地址:http://www.cnblogs.com/yutingliuyl/p/7110253.html