把combobox控件添加到datagridview控件中_自定义系列:控件属性添加
生活随笔
收集整理的這篇文章主要介紹了
把combobox控件添加到datagridview控件中_自定义系列:控件属性添加
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
本文講述如何在布局文件中添加原本所不具備的屬性,以PagerTabStrip控件為例,增加textColor與textSize屬性。
一、屬性聲明
新建res/values下的attrs.xml文件(文件名自取),在resources中增加declare-styleable,attr節點即擴展的屬性。
declare-styleable:其name屬性值為所修改的控件名;
attr:其name屬性為添加的屬性名,其format屬性為新屬性的數據類型。
<resources><declare-styleable name="myPagerTab"><attr name="android:textColor" format="color"/><attr name="android:textSize" format="dimension"/></declare-styleable> </resources>二、構造對象
新建類myPagerTab繼承自PagerTabStrip
2.1 重寫構造函數:構造函數一般需要重寫三種,分別是:
public myPagerTab(Context context)//在聲明對象時采用 public myPagerTab(Context context, AttributeSet attrs)//布局文件中引用時采用 public myPagerTab(Context context,AttributeSet attrs,int def)//在代碼中指定默認風格,其中第三個參數時參照類型(reference),使用方式參照《AS開發實戰》P192。2.2 重寫測量函數:onMeasure,非必須,僅在復雜視圖中重寫
2.3 重寫繪圖函數:在onLayout、onDraw、dispatchDraw中視情況重寫一個至多個
private int textColor = Color.BLUE; private int textSize = 30; @Override protected void onDraw(Canvas canvas) { // 繪制函數setTextColor(textColor); // 設置標題文字的文本顏色setTextSize(TypedValue.COMPLEX_UNIT_SP, textSize); // 設置標題文字的文本大小super.onDraw(canvas); }2.4 實現的myPagerTab控件文本效果
總結
以上是生活随笔為你收集整理的把combobox控件添加到datagridview控件中_自定义系列:控件属性添加的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: whea uncorrectable e
- 下一篇: python数字信号处理应用中文pdf_