2016-07-29 2 views
0

많은 시도를 해본 결과 R & D를 보았지만 EditText에서 자신 만의 오류 드로어 블을 보여줄 수 없었습니다.EditText에서 오류 텍스트 팝업

String str = "Please enter a valid email address”; 

// This line is used to give color to error text. 
ForegroundColorSpan colorSpan = new ForegroundColorSpan(Color.YELLOW); 

// This line is used to give background color to error text. 
BackgroundColorSpan backColorSpan = new BackgroundColorSpan(Color.BLUE); 

// This s basically a StringBuilder that implements CharSequence interface. 
SpannableStringBuilder strBuilder = new SpannableStringBuilder(str); 

strBuilder.setSpan(colorSpan, 0, str.length(), 0); 
EditText et = (EditText)findViewById(R.id.et); 
Drawable drawable = getResources().getDrawable(R.drawable.btn); 

// This line shows our own icon in place of default icon. 
setError(CharSequence, Drawable); 

So, strBuilder in next line is an implementation of CharSequence. 
et.setError(strBuilder, drawable); 

모든 해결 방법 : 다음

내 코드?

+0

코드와 이미지를 게시 할 수 있습니까? – Mussa

답변

0

구글 개발자들 보십시요.

drawable 객체에 setBound() 메소드를 호출해야합니다. 다음 줄을 넣어야합니다.

drawable.setBounds(0,0,drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight()); 
+0

제대로 작동했습니다. 감사. –

관련 문제