我在密码字段中使用了drawable right,但如果密码字段中出现错误,则不允许在其后更改drawable.错误之前它工作正常. @H_403_3@<EditText androID:ID="@+ID/edt_reg_password" androID:layout_height="wrap_content" androID:layout_below="@ID/edt_reg_email" androID:layout_margintop="@dimen/padding_normal" androID:drawableleft="@mipmap/ic_action_password" androID:drawableRight="@mipmap/ic_action_password_visibility" androID:drawablepadding="@dimen/padding_normal" androID:hint="@string/hint_password" androID:inputType="textPassword" androID:maxLength="25" androID:paddingleft="@dimen/padding_normal" tools:visibility="visible" />
用于更改眼睛图标运行时的Java代码
@H_403_3@private voID setPasswordDrawable() { final Drawable showpass_icon = getResources().getDrawable(R.mipmap.ic_action_password_visibility); final Drawable hIDepass_icon = getResources().getDrawable(R.mipmap.ic_action_password_visibility_off); final Drawable pass_drawable = getResources().getDrawable(R.mipmap.ic_action_password); pass_drawable.setBounds(0,pass_drawable.getIntrinsicWIDth(),pass_drawable.getIntrinsicHeight()); //edtPassword.setCompoundDrawables(pass_drawable,null,showpass_icon,null); edtPassword.setontouchListener(new VIEw.OntouchListener() { @OverrIDe public boolean ontouch(VIEw v,MotionEvent event) { if (edtPassword.getCompoundDrawables()[2] == null) { return false; } if (event.getAction() != MotionEvent.ACTION_UP) { return false; } if (event.getX() > edtPassword.getWIDth() - edtPassword.getpaddingRight() - showpass_icon.getIntrinsicWIDth()) { if (isPasswordVisible) { runOnUiThread(new Runnable() { @OverrIDe public voID run() { //edtPassword.setError(null); edtPassword.settransformationMethod( PasswordtransformationMethod.getInstance()); edtPassword.setSelection(edtPassword.getText().length()); showpass_icon.setBounds(0,showpass_icon.getIntrinsicWIDth(),showpass_icon.getIntrinsicHeight()); edtPassword.setCompoundDrawables(pass_drawable,null); } }); isPasswordVisible = false; } else { runOnUiThread(new Runnable() { @OverrIDe public voID run() { //edtPassword.setError(null); edtPassword.settransformationMethod( HIDeReturnstransformationMethod.getInstance()); edtPassword.setSelection(edtPassword.getText().length()); hIDepass_icon.setBounds(0,hIDepass_icon.getIntrinsicWIDth(),hIDepass_icon.getIntrinsicHeight()); edtPassword.setCompoundDrawables(pass_drawable,hIDepass_icon,null); } }); isPasswordVisible = true; } } return false; } }); }用于设置错误
@H_403_3@public voID setVIEwError(VIEw vIEw,String message){ if (vIEw instanceof EditText) { ((EditText) vIEw).setError(message); }} 解决方法 你可以用这个 – @H_403_3@if(error=true){ editText.setCompoundDrawablesWithIntrinsicBounds( 0,R.drawable.ic_error,0); editText.setCompoundDrawablepadding(5);}else{ editText.setCompoundDrawablesWithIntrinsicBounds( 0,R.drawable.ic_corrct,0); editText.setCompoundDrawablepadding(5);} 总结以上是内存溢出为你收集整理的android – 在编辑文本中可绘制,在错误后不更新全部内容,希望文章能够帮你解决android – 在编辑文本中可绘制,在错误后不更新所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)