android自定義控件和自定義回調(diào)函數(shù)步驟示例
自定義控件的步驟:
1 View的工作原理
2 編寫View類
3 為View類增加屬性
4 繪制屏幕
5 響應用戶消息
6 自定義回調(diào)函數(shù)
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"
/>
相關文章
Android組件ContextMenu實現(xiàn)長按事件
這篇文章主要為大家詳細介紹了Android組件ContextMenu實現(xiàn)長按事件,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下2021-04-04
Android自定義view之利用drawArc方法實現(xiàn)動態(tài)效果(思路詳解)
這篇文章主要介紹了Android自定義view之利用drawArc方法實現(xiàn)動態(tài)效果,drawArc方法包含了五個參數(shù),具體細節(jié)在本文中給大家提到過,需要的朋友可以參考下2021-08-08
android實現(xiàn)視頻的加密和解密(使用AES)
本篇文章主要介紹了android實現(xiàn)視頻的加密和解密(使用AES),小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-05-05
Android使用ContentProvider實現(xiàn)跨進程通訊示例詳解
這篇文章主要為大家介紹了Android使用ContentProvider實現(xiàn)跨進程通訊示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2023-03-03
Android使用TextView實現(xiàn)無下劃線超鏈接的方法
這篇文章主要介紹了Android使用TextView實現(xiàn)無下劃線超鏈接的方法,結合實例形式分析了Android中TextView超鏈接去除下劃線的相關實現(xiàn)技巧與注意事項,需要的朋友可以參考下2016-08-08
android studio 3.0 升級 項目遇到的問題及更改思路(問題小結)
Android Studio從3.0版本新增了許多功能,當然首當其沖就是從3.0版本新增了對 Kotlin 開發(fā)語言的支持,除此之外還有其他一些新功能。很多小伙伴在android studio 3.0 升級項目遇到很多問題,下面小編給大家分享一些問題小結及解決辦法,一起看看吧2017-11-11

