(Http://wallage.blog.163.com/blog/static/17389624201071823443675? Latestblog)
Android can inherit any control and write a custom beautiful control. To write custom data, you can continue Android. widget. edittext and rewrite other ondraw to get your own edit box.
Import Android. content. context;
Import Android. Graphics. Canvas;
Import Android. Graphics. color;
Import Android. Graphics. paint;
Import Android. util. attributeset;
Import Android. View. windowmanager;
Import Android. widget. edittext;
Public class teledit extends edittext {
Context mcontext;
Public teledit (context ){
Super (context );
Mcontext = context;
}
Public teledit (context, attributeset attrs ){
Super (context, attrs );
Mcontext = context;
}
Public teledit (context, attributeset attrs, int defstyle ){
Super (context, attrs, defstyle );
Mcontext = context;
}
Protected void ondraw (canvas)
{
Windowmanager WM = (windowmanager) mcontext. getsystemservice ("window ");
Int defaults wwidth = WM. getdefadisplay display (). getwidth ();
Int required wheight = WM. getdefaultdisplay (). getheight ();
Paint paint = new paint ();
Paint. setstyle (paint. style. Fill );
Paint. setcolor (color. Black );
Int paddingtop = getpaddingtop ();
Int paddingbottom = getpaddingbottom ();
Int scrolly = getscrolly ();
Int scrollx = getscrollx () + descriwwidth;
Int innerheight = scrolly + getheight ()-paddingtop-paddingbottom;
Int lineheight = getlineheight ();
Int Baseline = scrolly + (lineheight-(scrolly % lineheight ));
Int x = 8;
While (baseline <innerheight ){
// Canvas. drawbitmap (line, X, baseline + paddingtop, paint );
Canvas. drawline (x, baseline + paddingtop, scrollx, baseline + paddingtop, paint );
Baseline + = lineheight;
}
Super. ondraw (canvas );
}
}
Layout file:
<Com. XXX. Tel. Common. teledit
Android: text = "@ + ID/edittext01"
Android: Id = "@ + ID/edittext01"
Android: layout_width = "fill_parent"
Android: Background = "@ drawable/xxxx"
Android: gravity = "TOP"
Android: Typeface = "sans"
Android: Capitalize = "sentences"
Android: linespacingextra = "5dip"
Android: textsize = "22dip"
Android: textcolor = "@ color/wite"
Android: layout_height = "300dip">
</COM. XXX. Tel. Common. teledit>