手机
当前位置:查字典教程网 >编程开发 >安卓软件开发 >android自定义控件和自定义回调函数步骤示例
android自定义控件和自定义回调函数步骤示例
摘要:自定义控件的步骤:1View的工作原理2编写View类3为View类增加属性4绘制屏幕5响应用户消息6自定义回调函数java代码复制代码代码...

自定义控件的步骤:

1 View的工作原理

2 编写View类

3 为View类增加属性

4 绘制屏幕

5 响应用户消息

6 自定义回调函数

java代码

复制代码 代码如下:

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

复制代码 代码如下:

<?xml version="1.0" encoding="utf-8"?>

<>

<TextView

android:id="@+id/tabhost_tv"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

/>

【android自定义控件和自定义回调函数步骤示例】相关文章:

Android自定义图片质量的控件截图类代码

android 从资源中获取数组

Android中隐藏标题栏和状态栏的方法

Android 通过onDraw实现在View中绘图操作的示例

Android实现自定义带文字和图片Button的方法

android中自定义checkbox的图片和大小

Android列表实现(1)_数组列表实例介绍

Android中的Button自定义点击效果实例代码

Android的文本和输入之创建输入法教程

android之自定义Toast使用方法

精品推荐
分类导航