Android 开发TextView 部分字符高亮
2010-08-26 00:02:00 来源:WEB开发网}
public class TextHighlightUsage extends Activity {
TextHighlightHelper tHelper1;
TextHighlightHelper tHelper2;
LinearLayout ll;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ll = (LinearLayout)findViewById(R.id.layout);
//Text:HelloText2
CharSequence c1 = "HelloText2";
tHelper1 = new TextHighlightHelper(this,LinearLayout.HORIZONTAL);
tHelper1.addText(c1);
tHelper1.addColor(0, 3, Color.RED);
tHelper1.addBackResource(R.drawable.dot);
ll.addView(tHelper1.loadView());
//Text:创新源于模仿!
CharSequence c2 = "创新源于模仿!";
tHelper2 = new TextHighlightHelper(this,LinearLayout.VERTICAL);
tHelper2.addText(c2);
tHelper2.addColor(1, 3, Color.RED);
ll.addView(tHelper2.loadView());
}
}
7. emulator 运行截图:
至于其能不能满足需求 见仁见智了 大家可以参考截图
赞助商链接