android之EditText输入错误时该怎样提示用户
1) 使用Toast提示
1
Toast. makeText ( this,"邮箱格式不正确", Toast. LENGTH_LONG ). show ( ) ;
2) 使用EditText的setError提示
1
2
EditText et=(EditText ) findViewById (R. id. etTest ) ;
et. setError ( "有错误提示" ) ;
PS:在EditText的右边使用TextView来提示,类似于网页中注册页面。需要注意的是EditText必须获得焦点才会弹出错误提示框。
3) 自定义图标的setError提示
1
2
3
Drawable d= getResources ( ). getDrawable (R. drawable. ic_launcher ) ;
d. setBounds ( 0,0,30,30 ) ;//必须设置大小,否则不显示
et. setError ( "有错误提示", d ) ;