Android開發學習筆記-自訂群組合控制項的過程

來源:互聯網
上載者:User

標籤:des   android   style   http   io   使用   ar   for   檔案   

自訂群組合控制項的過程

1.自訂一個View 一般來說,繼承相對布局,或者線性布局 ViewGroup;
2.實現父類的構造方法。一般來說,需要在構造方法裡初始化自訂的布局檔案;
3.根據一些需要或者需求,定義一些API方法;

----------------------------------
4.根據需要,自訂控制項的屬性,可以參照TextView屬性;

5.自訂命名空間,例如:
xmlns:itheima="http://schemas.android.com/apk/res/《包名》"
xmlns:itheima="http://schemas.android.com/apk/res/com.itheima.mobilesafe"

6.自訂我們的屬性,在Res/values/attrs.xml

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

<declare-styleable name="TextView">
<attr name="title" format="string" />
<attr name="desc_on" format="string" />
<attr name="desc_off" format="string" />
</declare-styleable>

</resources>

7.使用我們自訂的屬性
例如:
itheima:title="設定自動更新"
itheima:desc_on="設定自動更新已經開啟"
itheima:desc_off="設定自動更新已經關閉"

8.在我們自訂控制項的帶有兩個參數的構造方法裡AttributeSet attrs 取出我們的屬性值,關聯自訂布局檔案對應的控制項;

Android開發學習筆記-自訂群組合控制項的過程

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.