To customize a control:
1 Working principle of view
2 Writing View class
3 Adding attributes to the view class
4 Drawing Screen
5 Responding to user messages
6 Custom Callback Functions
Java code
Copy Code code as follows:
Private class MyText extends LinearLayout {
Private TextView Text1;
/*
* Private String text;
*
* Public String GetText () {return text;}
*
* public void SetText (String text) {this.text = text;}
*/
Public MyText {
Super (context);
TODO auto-generated Constructor stub
Layoutinflater inflate = (layoutinflater) context
. Getsystemservice (context. Layout_inflater_service);
View view = Inflate.inflate (R.layout.tabhost_item, this, true);
Text1 = (TextView) View.findviewbyid (R.ID.TABHOST_TV);
}
public void Settextviewtext (String tabhost_name) {
Text1.settext (Tabhost_name);
}
/*
* @Override protected void OnDraw (Canvas Canvas) {//TODO
* Auto-generated Method Stub super.ondraw (canvas); Paint p = new
* Paint (); P.setcolor (Color.White); P.settextsize (10);
* Canvas.drawtext (text, n, p); }
*/
}
XML code
Copy Code code as follows:
<?xml version= "1.0" encoding= "Utf-8"?>
<!--self-layout of custom control mytext in Gmaptabactivity-->
<textview
Android:id= "@+id/tabhost_tv"
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
/>