Android EditText.setError()-popupwindowがポップアップされ、効果的です

813 ワード

SetErrorは以下の2つの方法を提供した:1.カスタム文字public void setError(CharSequence error)2を表示する.カスタム文字とアイコンを表示public void setError(CharSequence error,Drawable icon)デフォルトでは、App設定のトピックなどの理由で設定した文字とアイコンが表示されない場合がありますので、以下の方法を参照してください.
                //      
		String errorText = "   ~~!";
		//        
		Drawable errorIcon = getResources().getDrawable(R.drawable.icon_error);
		//       
		errorIcon.setBounds(new Rect(0, 0, errorIcon.getIntrinsicWidth(),
				errorIcon.getIntrinsicHeight()));
		//          
		ForegroundColorSpan fgcspan = new ForegroundColorSpan(Color.RED);
		SpannableStringBuilder ssbuilder = new SpannableStringBuilder(errorText);
		ssbuilder.setSpan(fgcspan, 0, errorText.length(), 0);
		//  
		et_content.setError(ssbuilder, errorIcon);
		et_content.requestFocus();