android自定义控件和自定义回调函数步骤示例
自定义控件的步骤:
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"?>
<!-- GMapTabActivity中自定义控件MyText的自布局 -->
<TextView
android:id="@+id/tabhost_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
相关文章
在当前Activity之上创建悬浮view之WindowManager悬浮窗效果
这篇文章主要介绍了在当前Activity之上创建悬浮view之WindowManager悬浮窗效果的相关资料,需要的朋友可以参考下2016-01-01
Android时间日期拾取器学习使用(DatePicker、TimePicker)
这篇文章主要为大家详细介绍了Android提供的DatePicker日期拾取器和TimePicker时间拾取器的相关资料,具有一定的参考价值,感兴趣的小伙伴们可以参考一下2017-02-02
Android编程使WebView支持HTML5 Video全屏播放的解决方法
这篇文章主要介绍了Android编程使WebView支持HTML5 Video全屏播放的解决方法,较为详细的分析了全屏播放所涉及的相关技巧,并给出了完整代码下载地址供读者参考,需要的朋友可以参考下2015-10-10


最新评论