自定义控件的步骤: 1 View的工作原理2 编写View类3 为View类增加属性4 绘制屏幕5 响应用户消息6 自定义回调函数 java代码 代码如下:private c
自定义控件的步骤:
1 View的工作原理
2 编写View类
3 为View类增加属性
4 绘制屏幕
5 响应用户消息
6 自定义回调函数
java代码
代码如下:
private class MyText extends LinearLayout {
private TextView text1;
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);
}
}
xml代码
代码如下:
<?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"
/>
--结束END--
本文标题: android自定义控件和自定义回调函数步骤示例
本文链接: https://www.lsjlt.com/news/27262.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-01-21
2023-10-28
2023-10-28
2023-10-27
2023-10-27
2023-10-27
2023-10-27
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0