之前想做这样一个效果,
如图:
[img]http://dl.iteye.com/upload/picture/pic/98913/fbfd6d9f-3831-314c-9aef-1cef1daf8c2c.png[/img]
之前的code:
这个是实现不了的.
后来发现EditView的selectAll()属性.
该属性意味选中当前所有文本。
修改之后:
这样,文本背景色设定OK.
效果:
[img]http://dl.iteye.com/upload/picture/pic/98915/dcbc8136-1f7f-3313-8b82-22f2eeb46af1.png[/img]
如果还要设定文本字体颜色,如上如一样。
可以这样去做:
效果:
[img]http://dl.iteye.com/upload/picture/pic/98917/fcbfec44-c623-3e26-b20d-6e5f43714cdc.png[/img]
如图:
[img]http://dl.iteye.com/upload/picture/pic/98913/fbfd6d9f-3831-314c-9aef-1cef1daf8c2c.png[/img]
之前的code:
et = (EditText) findViewById(R.id.et);
String text = "<font style='background-color:#FFCCFF'>"+"123456789"+"</font>";
et.setText(Html.fromHtml(text));
这个是实现不了的.
后来发现EditView的selectAll()属性.
该属性意味选中当前所有文本。
修改之后:
et = (EditText) findViewById(R.id.et);
String text = "123456456";
et.setText(text);
et.selectAll();//设定全部选中
et.setHighlightColor(Color.BLUE);//设定选中背景色
这样,文本背景色设定OK.
效果:
[img]http://dl.iteye.com/upload/picture/pic/98915/dcbc8136-1f7f-3313-8b82-22f2eeb46af1.png[/img]
如果还要设定文本字体颜色,如上如一样。
可以这样去做:
et = (EditText) findViewById(R.id.et);
String text = "123456456";
et.setText(Html.fromHtml("<font color=red>"+text+"</font>"));
et.selectAll();//设定全部选中
et.setHighlightColor(Color.BLUE);//设定选中背景色
效果:
[img]http://dl.iteye.com/upload/picture/pic/98917/fcbfec44-c623-3e26-b20d-6e5f43714cdc.png[/img]