最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android編程Widget創(chuàng)建與使用方法簡明教程

 更新時間:2016年10月27日 09:31:45   作者:Wallace  
這篇文章主要介紹了Android編程Widget創(chuàng)建與使用方法,結(jié)合實例形式分析了Widget的功能、使用方法與相關(guān)注意事項,需要的朋友可以參考下

本文實例講述了Android編程Widget創(chuàng)建與使用方法。分享給大家供大家參考,具體如下:

Android reference中有關(guān)于如何建立一個Widget的詳細方法,這里簡要說明一下,詳情可以查看Android SDK中自帶的reference。

要建立一個Widget,分為如下幾個步驟:

(1) 創(chuàng)建一個類,讓其繼承類AppWidgetProvider,在AppWidgetProvider中有許多方法,例如onDelete(Context,int[]),onEnable(Context)等,但一般情況下我們只是覆寫onUpdate(Context,AppWidgetManager,int[])方法。在該方法中,我們啟動后臺服務的類,一般是啟動Thread類或者Android中的Service類。在該類中我們進行從服務器端獲得數(shù)據(jù)并進行處理并在Widget中顯示。

(2) 在你的AndroidMenifest.xml中添加一個receiver標簽,讓其指向你的AppWidgetProvider子類。內(nèi)容如下:

<receiver android:name="JiwaiWidget"
android:label="@string/app_name"
android:icon="@drawable/jiwai">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
<meta-data android:name="android.appwidget.provider"
      android:resource="@xml/info" />
</receiver>

對上面的代碼進行解釋:

第一行指定該Widget的接收者是JiwaiWidget,即你建立的AppWidgetProvider子類;

第二行指定該Widget的標簽名稱,值為value目錄下string.xml中的app_name值;

第三行指定該Widget的圖標,值為drawable目錄下jiwai圖片;

第四行-第六行是采用Android文檔中提供的;

第七行指定該Widget的描述者信息,該描述著中定義了Widget的相關(guān)信息,如該Widget的寬度、長度、自動更新的間隔時間等信息,該描述位于xml目錄下的info.xml中。

(3) 編寫你的Widget的provider文件信息(本例中是xml/info.xml)

<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
  android:minWidth="200dp"
  android:minHeight="90dp"
  android:updatePeriodMillis="43200000"
  android:initialLayout="@layout/appwidget"
  android:configure="com.lawrenst.jiwai.JiwaiConfigure">
</appwidget-provider>

其中android:updatePeriodMillis是自動更新的時間間隔,android:initialLayout是Widget的界面描述文件。Android:configure是可選的,如果你的Widget需要在啟動時先啟動一個Activity,則需要設定該項為你的Activity。本例中,需要你的嘀咕帳號和密碼,所以應先顯示一個Activity,輸入你的賬號和密碼,然后將得到的信息在你的Widget中顯示。

(4) 在layout目錄下編寫appwidget.xml文件,配置你的Widget的界面信息:

<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="@+id/widget"
android:background="@drawable/title_a">
<LinearLayout android:layout_width="fill_parent"
android:orientation="horizontal"
android:layout_height="wrap_content"
android:background="@drawable/title">
<TextView android:id="@+id/username_display"
android:textStyle="bold"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:textColor="#ffffff"
android:textSize="15px"
android:gravity="left|center_vertical"
android:paddingLeft="6px" />
</LinearLayout>
<LinearLayout android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView android:id="@+id/text1"
android:layout_width="fill_parent"
android:textColor="#ffffff"
android:textSize="12px"
android:gravity="center_vertical|left"
android:paddingLeft="6px"
android:layout_height="30px">
</TextView>
<TextView android:id="@+id/text2"
android:textColor="#ffffff"
android:layout_height="30px"
android:gravity="center_vertical|left"
android:textSize="12px"
android:paddingLeft="6px"
android:layout_width="fill_parent">
</TextView>
</LinearLayout>
</LinearLayout>

該Widget中包括三個Textview,兩個用來顯示嘰歪的信息,一個用來顯示用戶名,上述代碼比較簡單,故不做解釋。

(5) 由于需要一個Acvivity對象用來輸入賬戶信息,所以在layout目錄下新建一個login.xml,作為Activity的配置文件:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  >
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
android:textColor="#ff8c00"
android:capitalize="characters"
android:textStyle="bold" />
<LinearLayout android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal">
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/user"
android:textColor="#ff8cff"
android:capitalize="characters" />
<EditText android:id="@+id/username"
android:layout_width="200px"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal">
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/code"
android:textColor="#ff8cff"
android:capitalize="characters" />
<EditText android:id="@+id/password"
android:layout_width="200px"
android:layout_height="wrap_content"
android:password="true" />
</LinearLayout>
<LinearLayout android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal">
<Button
  android:id="@+id/submit"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:text="Submit" 
  />
</LinearLayout>
</LinearLayout>

有兩個EditText用來輸入用戶名和密碼,另外還有一個Button對象。
準備工作差不多了,下面就可以寫代碼了。

這里再分享一個案例供大家參考:http://m.fzitv.net/books/40184.html

更多關(guān)于Android相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Android基本組件用法總結(jié)》、《Android開發(fā)入門與進階教程》、《Android資源操作技巧匯總》、《Android視圖View技巧總結(jié)》及《Android控件用法總結(jié)

希望本文所述對大家Android程序設計有所幫助。

相關(guān)文章

  • Android App自動更新之通知欄下載

    Android App自動更新之通知欄下載

    這篇文章主要為大家詳細介紹了Android App自動更新之通知欄下載功能,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2018-06-06
  • Android 軟鍵盤彈出時把原來布局頂上去的解決方法

    Android 軟鍵盤彈出時把原來布局頂上去的解決方法

    本文主要介紹了Android軟鍵盤彈出時把原來布局頂上去的解決方法。具有一定的參考作用,下面跟著小編一起來看下吧
    2017-01-01
  • Android給圖片加文字和圖片水印實例代碼

    Android給圖片加文字和圖片水印實例代碼

    本篇文章主要介紹了Android給圖片加文字和圖片水印實例代碼,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-04-04
  • Android?Studio支持安卓手機投屏功能詳解

    Android?Studio支持安卓手機投屏功能詳解

    這篇文章主要給大家介紹了關(guān)于Android?Studio支持安卓手機投屏功能的相關(guān)資料,文中通過圖文介紹的非常詳細,對有需要的朋友具有一定的參考學習價值,需要的朋友可以參考下
    2023-01-01
  • Android自定義可控制速度的跑馬燈

    Android自定義可控制速度的跑馬燈

    這篇文章主要為大家詳細介紹了Android自定義可控制速度的跑馬燈,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-06-06
  • 解決webview 第二次調(diào)用loadUrl頁面不刷新的問題

    解決webview 第二次調(diào)用loadUrl頁面不刷新的問題

    這篇文章主要介紹了解決webview 第二次調(diào)用loadUrl頁面不刷新的問題,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-03-03
  • Android仿外賣購物車功能

    Android仿外賣購物車功能

    這篇文章主要為大家詳細介紹了Android仿外賣購物車功能的相關(guān)資料,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-06-06
  • 淺析KJFrameForAndroid框架如何高效加載Bitmap

    淺析KJFrameForAndroid框架如何高效加載Bitmap

    Bitmap是Android系統(tǒng)中的圖像處理的最重要類之一。用它可以獲取圖像文件信息,進行圖像剪切、旋轉(zhuǎn)、縮放等操作,并可以指定格式保存圖像文件。本文主要是從KJFrameForAndroid框架中分析高效加載Bitmap的方法
    2014-07-07
  • Android FaceDetector實現(xiàn)人臉檢測功能

    Android FaceDetector實現(xiàn)人臉檢測功能

    這篇文章主要為大家詳細介紹了Android FaceDetector實現(xiàn)人臉檢測功能,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2018-05-05
  • RxJava2 線程調(diào)度的方法

    RxJava2 線程調(diào)度的方法

    這篇文章主要介紹了RxJava2 線程調(diào)度的方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2019-03-03

最新評論

武乡县| 合作市| 鄢陵县| 乌拉特前旗| 五莲县| 鹤峰县| 西乌珠穆沁旗| 聂荣县| 南陵县| 卢氏县| 灵宝市| 怀安县| 扶沟县| 祥云县| 增城市| 彭水| 康保县| 石屏县| 库车县| 东辽县| 万荣县| 神池县| 纳雍县| 周宁县| 聂荣县| 察隅县| 高阳县| 水富县| 马鞍山市| 桦川县| 甘孜县| 武强县| 满城县| 策勒县| 即墨市| 大连市| 灵宝市| 贵德县| 新宁县| 都江堰市| 丰宁|