EditText setError() with icon but without Popup message

后端 未结 6 1121
你的背包
你的背包 2020-11-27 03:11

I want to to have some validation for my EditText wherein I want to show \"\" icon (that comes when you put editText.setError(\"blah blah\")) but don\'t want th

6条回答
  •  遥遥无期
    2020-11-27 03:53

    You dont need to create a new EditText class or change xml. The solution is very simple:

    Edittext editText= (EditText) rootView.findViewById(R.id.email);
    
    String str= editText.getText().toString();
    
    if(str.equalsIgnoreCase("") ){
    
                    Drawable dr = getResources().getDrawable(R.drawable.error); 
                                     //add an error icon to yur drawable files
                    dr.setBounds(0, 0, dr.getIntrinsicWidth(), dr.getIntrinsicHeight());
    
                    editText.setCompoundDrawables(null,null,dr,null);
    
                }
    

提交回复
热议问题