成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

Android Widget開發學習教程(二)

移動開發
Android Widget開發學習教程是本文要介紹的內容,主要是來了解并學習Android Widget的應用,具體內容的詳解來看本文。

Android Widget開發學習教程是本文要介紹的內容,主要是來了解并學習Android Widget的應用,繼續 Android Widget開發學習筆記(一)繼續講解。本文具體內容的實現來看本文詳解。

為了實現一個手機Android平臺的Widget,該Widget中的內容是根據輸入賬號從嘰歪網站上獲得得。當然,這個過程需要嘰歪的API,得到信息后進行處理并顯示出來。大體流程就是這樣。好了,進入第一步。

該嘰歪賬號是測試賬號,用戶名是“students”,密碼是“111111” 請不要擅自更改。

2. 建立一個Widget

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

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

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

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

  1. <receiver android:name="JiwaiWidget"   
  2. android:label="@string/app_name"   
  3. android:icon="@drawable/jiwai">   
  4. <intent-filter>   
  5. <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />   
  6. </intent-filter>   
  7. <meta-data android:name="android.appwidget.provider"   
  8.             android:resource="@xml/info" />   
  9. </receiver>  

對上面的代碼進行解釋:

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

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

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

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

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

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

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

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

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

  1. <?xml version="1.0" encoding="UTF-8"?>   
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"   
  3. android:layout_width="fill_parent"   
  4. android:layout_height="wrap_content"   
  5. android:orientation="vertical"   
  6. android:id="@+id/widget"   
  7. android:background="@drawable/title_a">   
  8. <LinearLayout android:layout_width="fill_parent"   
  9. android:orientation="horizontal"   
  10. android:layout_height="wrap_content"   
  11. android:background="@drawable/title">   
  12. <TextView android:id="@+id/username_display"   
  13. android:textStyle="bold"   
  14. android:layout_width="wrap_content"   
  15. android:layout_height="fill_parent"   
  16. android:textColor="#ffffff"   
  17. android:textSize="15px"   
  18. android:gravity="left|center_vertical"   
  19. android:paddingLeft="6px" />   
  20. </LinearLayout>   
  21.  
  22. <LinearLayout android:orientation="vertical"   
  23. android:layout_width="fill_parent"   
  24. android:layout_height="fill_parent">   
  25.  
  26. <TextView android:id="@+id/text1"   
  27. android:layout_width="fill_parent"   
  28. android:textColor="#ffffff"   
  29. android:textSize="12px"   
  30. android:gravity="center_vertical|left"   
  31. android:paddingLeft="6px"   
  32. android:layout_height="30px">   
  33. </TextView>   
  34.  
  35. <TextView android:id="@+id/text2"   
  36. android:textColor="#ffffff"   
  37. android:layout_height="30px"   
  38. android:gravity="center_vertical|left"   
  39. android:textSize="12px"   
  40. android:paddingLeft="6px"   
  41. android:layout_width="fill_parent">   
  42. </TextView>   
  43. </LinearLayout>   
  44. </LinearLayout>  

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

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

  1. <?xml version="1.0" encoding="utf-8"?>   
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"   
  3.     android:orientation="vertical"   
  4.     android:layout_width="fill_parent"   
  5.     android:layout_height="fill_parent"   
  6.     >   
  7. <TextView android:layout_width="fill_parent"   
  8. android:layout_height="wrap_content"   
  9. android:text="@string/hello"   
  10. android:textColor="#ff8c00"   
  11. android:capitalize="characters"   
  12. android:textStyle="bold" />   
  13.  
  14. <LinearLayout android:orientation="horizontal"   
  15. android:layout_width="fill_parent"   
  16. android:layout_height="wrap_content"   
  17. android:gravity="center_horizontal">   
  18.  
  19. <TextView android:layout_width="wrap_content"   
  20. android:layout_height="wrap_content"   
  21. android:text="@string/user"   
  22. android:textColor="#ff8cff"   
  23. android:capitalize="characters" />   
  24.  
  25. <EditText android:id="@+id/username"   
  26. android:layout_width="200px"   
  27. android:layout_height="wrap_content" />   
  28.  
  29. </LinearLayout>   
  30.  
  31. <LinearLayout android:orientation="horizontal"   
  32. android:layout_width="fill_parent"   
  33. android:layout_height="wrap_content"   
  34. android:gravity="center_horizontal">   
  35.  
  36. <TextView android:layout_width="wrap_content"   
  37. android:layout_height="wrap_content"   
  38. android:text="@string/code"   
  39. android:textColor="#ff8cff"   
  40. android:capitalize="characters" />   
  41.  
  42. <EditText android:id="@+id/password"   
  43. android:layout_width="200px"   
  44. android:layout_height="wrap_content"   
  45. android:password="true" />   
  46. </LinearLayout>   
  47.  
  48. <LinearLayout android:orientation="horizontal"   
  49. android:layout_width="fill_parent"   
  50. android:layout_height="wrap_content"   
  51. android:gravity="center_horizontal">   
  52.  
  53. <Button   
  54.     android:id="@+id/submit"   
  55.     android:layout_width="wrap_content"   
  56.     android:layout_height="wrap_content"   
  57.     android:text="Submit"     
  58.     />   
  59. </LinearLayout>   
  60. </LinearLayout>  

有兩個EditText用來輸入用戶名和密碼,另外還有一個Button對象。

小結:Android Widget開發學習教程的內容介紹完了,希望通過Android Widget內容的學習能對你有幫助!

責任編輯:zhaolei 來源: iteye
相關推薦

2011-09-07 13:42:36

Android Wid實例

2011-09-07 10:34:48

Android Wid

2011-09-07 11:15:25

2011-09-09 16:38:51

Android Wid源碼

2011-09-09 20:14:58

Android Wid

2010-07-13 09:02:19

Widget開發

2011-09-07 16:28:46

QT WidgetQWidget

2010-06-13 09:45:35

Widget開發

2011-09-07 17:54:40

Android Wid開發

2011-09-09 10:00:20

Android Wid開發

2010-07-23 08:54:02

2011-09-07 17:19:16

Web widget

2011-09-08 15:40:45

Android Wid組件

2011-09-08 13:11:07

Android Wid實例

2011-09-08 09:38:46

HTML5 WidgeDojo

2011-09-07 14:39:47

Android Wid設計

2013-12-26 15:18:09

Android開發安裝開發環境

2011-09-07 14:25:53

Android Wid設計

2011-09-09 11:05:56

Widget

2011-05-03 15:13:23

BlackBerryWidget
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 日韩字幕一区 | 人人艹人人爽 | 日本视频免费 | 欧美美乳 | 欧美a级网站 | 欧美一级黄色片在线观看 | 亚洲国产成人在线视频 | 欧美亚洲一区二区三区 | 在线观看视频91 | 久久久精品国产 | 狠狠躁18三区二区一区 | 国产91av视频在线观看 | 精品一区国产 | 欧美4p | 国产精品久久777777 | 国产精品不卡一区 | 97精品国产 | 国产精品网页 | 曰韩一二三区 | 91精品久久久久久久久中文字幕 | 日本手机看片 | 精品免费国产视频 | 成人1区2区| 欧美日韩中文字幕在线 | 日韩欧美在线不卡 | www.99热这里只有精品 | 欧美中文字幕一区二区三区亚洲 | 久久伊人一区二区 | 午夜电影在线播放 | 伦理二区| 日本精品999 | 亚洲精品免费在线观看 | 日韩一级欧美一级 | a欧美| 精品一区二区三区在线观看 | 日本久久综合 | 国产一区二区小视频 | 色男人的天堂 | 国产精品美女在线观看 | 国产精品视频网 | 午夜精品福利视频 |