Android custom controls and custom callback function steps Sample _android

Source: Internet
Author: User
Tags stub

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-->

Android:id= "@+id/tabhost_tv"
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.