干货首发,可以清理,带动画的自定义控件CuteEditText

来源:互联网 发布:史记的地位 知乎 编辑:程序博客网 时间:2024/04/30 17:30

转载请注明出处:王亟亟的大牛之路

总想创造个什么,但是又不知道要具体做什么。那么只有丛一直用的那些东西上面开始创造,哈哈。然后再摸索的过程中进步吧!

先上一下效果:
这里写图片描述

这种带删除按钮的形式还是蛮多的吧?但是一般怎么做?

拿一个布局然后里面套一个EditText+一个Button啊或ImageView啊,然后在Activity中还要反复的FindViewByID的操作。

这些事情CuteEditText都可以完成,而且还能根据用户输入的长度等进行判断哦!

只需要一个类+动画所需的Anim就可以完成,非常的轻量级,只有这些
这里写图片描述

How to Use?

<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:wjj="http://schemas.android.com/apk/res-auto"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:paddingBottom="@dimen/activity_vertical_margin"    android:paddingLeft="@dimen/activity_horizontal_margin"    android:paddingRight="@dimen/activity_horizontal_margin"    android:paddingTop="@dimen/activity_vertical_margin">    <cuteedittextpro.pro.wjj.cuteedittext.CuteEditTextPro.CuteEditText        android:layout_width="250dp"        android:layout_height="wrap_content"        wjj:text_hint="@string/cute_text_hint"        wjj:text_maxLength="10"        wjj:text_minLength="6"        wjj:text_anim_Type="Wobble"        android:layout_centerHorizontal="true"></cuteedittextpro.pro.wjj.cuteedittext.CuteEditTextPro.CuteEditText></RelativeLayout>

布局文件里面直接拽进去,简单的设置一些参数就能用。

当然,记得在你的Activity里findviewbyid一下,不然空指针你懂的。

一系列用Java代码配置和设置的代码也已经为大家写好了,看这里:

//设置动画效果    public void setAnim(String anim) {        Default_Anim_Type = anim;    }    //获取动画效果    public String getAnim() {        return Default_Anim_Type;    }    //设置最小值    public void setDefault_MinLength(int length){        Default_MinLength=length;    }    //设置最大值    public void setDefault_MaxLength(int length){        Default_MaxLength=length;    }    //设置hint    public void setDefault_Hint(String value){        Default_Hint=value;    }    //获取输入的值    public String getTextValue(){        return editText.getText().toString().trim();    }

要获取用户输入的值getTextValue()一下就好了,并且返回的值一定是符合你的字数逻辑的哦!

还有一些常用可能涉及到的逻辑和内容之后的更新会加以补充诸如 EditText的种类(密码,邮箱,数字等),是否需要禁止动画等,这个观众老爷可以自己根据自己的需求来添加。

源码地址:https://github.com/ddwhan0123/CuteEditTextGit

这里写图片描述

记得点个赞哦!!

3 0