<span style="font-family:Consolas;color:#ff0000;">拒绝转载,拒绝抄袭,代码虽然写的烂(赶项目),希望还是能帮助到某些人...</span>
<span style="font-family: Consolas; font-size: 10.5pt;">package xx.uicontrol.view;</span>
import android.content.Context; import android.content.res.TypedArray; import android.graphics.Color; import android.os.Build; import android.text.Editable; import android.text.InputType; import android.text.Selection; import android.text.TextWatcher; import android.text.method.DigitsKeyListener; import android.util.AttributeSet; import android.view.Gravity; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.EditText; import android.widget.ImageView; import android.widget.RelativeLayout; import android.widget.TextView; import xxx.R; import xxx.DensityUtils; /** * 文本框控件 on xlzhen 8/15 2015. */ public class InputView extends RelativeLayout { private TextView left_hint, right_message;//左边的文本提示,右边的输入文本提示 private EditText editText;//文本框 private View view_spacing;//顶部的间距线 private RelativeLayout rela_layout;//包含所有控件的布局文件,可以在里面addView private ImageView LeftImageView; private String left_hints, right_ok, right_error, right_max, right_min, edit_hint, edit_regex, edit_digits, view_spacing_visibility, left_text_type, edit_type, right_text; private int left_img, edit_min, edit_max, right_error_color, edit_height, edit_id;//edit_id 0:默认比较字符串大小 1:比较价格大小 2:银行卡号智能输入 private boolean edit_singleline; public int input_state = 1;//0:可以使用 1:不符合规范 2:字数过少 3:字数过多 private double edit_bj_max = 0; private int margin_top, margin_bottom; public InputView(Context context, AttributeSet attrs) { super(context, attrs); LayoutInflater.from(context).inflate(R.layout.input_edit_layout, this, true); initData(context, attrs); } /* *通过attr初始化控件 *left_hints 文本框左边的描述文本string * right_ok 文本框右边的文本提示(输入正确) * right_error 文本框右边的文本提示(输入错误,比如不符合规范,一般是跟在正则匹配错误的情况) * right_max 文本框右边的文本提示(输入的字数超过长度) * right_min 文本框右边的文本提示(输入的字数少于指定的长度) * edit_hint 文本框内的文本提示 * edit_regex 输入文本的正则匹配规则,输入后匹配规则 * edit_digits 允许输入的字符,输入前就过滤掉其他字符 * left_text_type 文本框左边的描述文本的左边一个小的提示文本,比如选填,必填,或者* * edit_type 文本输入类型,比如只允许输入数值TYPE_CLASS_NUMBER,或者密码TYPE_TEXT_VARIATION_PASSWORD,或者TYPE_CLASS_PHONE 电话号码规则 * left_offset 文本框左边的描述文本的长度 * edit_min 文本框内字符长度规范(最小) * edit_max 文本框内字符长度规范(最大) * edit_id 文本框内字符串输入时给用户看到的规范 0:普通的规范(字符长度匹配),1:数值比较大小(转换成int类型后比较传进来的数值大小),2:银行卡类型,四位一空 * right_error_color 文本框输入不规范时(不符合规则,过长,过短)文本提示颜色 * edit_height 文本框长度,默认45*1,xml那边只要输入1即可,需要多行输入的文本框则输入其他值比如2,3,4,5。 * view_spacing_visibility 控件顶部线条是否隐藏 * edit_bj_max 文本框内输入的数值和它比较 * edit_singleline 文本内容是否单行?默认单行 * */ public void initData(Context context, AttributeSet attrs) { rela_layout = (RelativeLayout) findViewById(R.id.rela_layout); TypedArray typedArray = getContext().obtainStyledAttributes(attrs, R.styleable.InputView); /*初始化string*/ left_hints = typedArray.getString(R.styleable.InputView_left_hint); right_ok = typedArray.getString(R.styleable.InputView_right_message); right_error = typedArray.getString(R.styleable.InputView_right_error); right_max = typedArray.getString(R.styleable.InputView_right_max); right_min = typedArray.getString(R.styleable.InputView_right_min); edit_hint = typedArray.getString(R.styleable.InputView_edit_hint); edit_regex = typedArray.getString(R.styleable.InputView_edit_regex); edit_digits = typedArray.getString(R.styleable.InputView_edit_digits); left_text_type = typedArray.getString(R.styleable.InputView_left_text_type); edit_type = typedArray.getString(R.styleable.InputView_edit_type); right_text = typedArray.getString(R.styleable.InputView_right_text); /*初始化int*/ left_img = typedArray.getResourceId(R.styleable.InputView_left_img, R.mipmap.icon5); edit_min = typedArray.getInteger(R.styleable.InputView_edit_min, 0); edit_max = typedArr
自定义控件>智能文本框(InputView)
最新推荐文章于 2023-05-22 15:49:07 发布