亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

android自定義控件和自定義回調(diào)函數(shù)步驟示例

 更新時間:2014年01月11日 14:32:15   作者:  
這篇文章主要介紹了android自定義控件步驟示例,包括為View類增加屬性、響應(yīng)用戶消息、自定義回調(diào)函數(shù)等方法

自定義控件的步驟:

1 View的工作原理
2 編寫View類
3 為View類增加屬性
4 繪制屏幕
5 響應(yīng)用戶消息
6 自定義回調(diào)函數(shù)

java代碼

復(fù)制代碼 代碼如下:

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(Context context) {
        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, 25, 25, p); }
     */

}

xml代碼

復(fù)制代碼 代碼如下:

<?xml version="1.0" encoding="utf-8"?>
<!-- GMapTabActivity中自定義控件MyText的自布局 -->

<TextView
    android:id="@+id/tabhost_tv"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
     />

相關(guān)文章

最新評論