标签:
参考:
Demo:
private SpannableStringBuilder content = new SpannableStringBuilder(); private static final ForegroundColorSpan STYLE_ERROR = new ForegroundColorSpan(Color.RED); private static final ForegroundColorSpan STYLE_INFO = new ForegroundColorSpan(Color.BLACK); private int start = 0; private int end = 0; public void appendLog(String msg,int type){ TextView logView = (TextView)findViewById(R.id.logView); content.append(msg); start = end; end += msg.length(); switch (type){ case Log.TYPE_ERROR: content.setSpan(STYLE_ERROR,start,end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); break; case Log.TYPE_INFO: content.setSpan(STYLE_INFO,start,end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); break; default: break; } if(logView!=null){ logView.setText(content); //scroll to the end int offset = logView.getLineCount() * logView.getLineHeight(); if(offset > logView.getHeight()){ logView.scrollTo(0,offset - logView.getHeight()); } } }
标签:
原文地址:http://www.cnblogs.com/tt2015-sz/p/5613052.html