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

Android Widget開發詳解

移動開發
Widget開發有很多值得學習的地方,你對他的概念是否熟悉,本文向大家繼續介紹一下,希望本文的介紹能讓你有所收獲。

本文和大家重點學習一下Widget開發的概念,本例是為了實現一個手機Android平臺的Widget開發,該Widget中的內容是根據輸入賬號從嘰歪網站上獲得得。當然,這個過程需要嘰歪的API,得到信息后進行處理并顯示出來。大體流程就是這樣。好了,進入***步。

Android Widget開發系列(二)

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

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

要建立一個Widget開發程序,分為如下幾個步驟:

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

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

  1. <receiverandroid:namereceiverandroid:name="JiwaiWidget" 
  2. android:label="@string/app_name" 
  3. android:icon="@drawable/jiwai"> 
  4. <intent-filter> 
  5. <actionandroid:nameactionandroid:name="android.appwidget.action.APPWIDGET_UPDATE"/> 
  6. </intent-filter> 
  7. <meta-dataandroid:namemeta-dataandroid: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-providerxmlns:androidappwidget-providerxmlns: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. <?xmlversionxmlversion="1.0"encoding="UTF-8"?> 
  2. <LinearLayoutxmlns:androidLinearLayoutxmlns: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. <LinearLayoutandroid:layout_widthLinearLayoutandroid:layout_width="fill_parent" 
  9. android:orientation="horizontal" 
  10. android:layout_height="wrap_content" 
  11. android:background="@drawable/title"> 
  12. <TextViewandroid:idTextViewandroid: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. <LinearLayoutandroid:orientationLinearLayoutandroid:orientation="vertical" 
  23. android:layout_width="fill_parent" 
  24. android:layout_height="fill_parent"> 
  25.  
  26. <TextViewandroid:idTextViewandroid: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. <TextViewandroid:idTextViewandroid: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> 
  45.  

 


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

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

 

  1. <?xmlversionxmlversion="1.0"encoding="utf-8"?> 
  2. <LinearLayoutxmlns:androidLinearLayoutxmlns: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. <TextViewandroid:layout_widthTextViewandroid: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. <LinearLayoutandroid:orientationLinearLayoutandroid:orientation="horizontal" 
  15. android:layout_width="fill_parent" 
  16. android:layout_height="wrap_content" 
  17. android:gravity="center_horizontal"> 
  18.  
  19. <TextViewandroid:layout_widthTextViewandroid: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. <EditTextandroid:idEditTextandroid:id="@+id/username" 
  26. android:layout_width="200px" 
  27. android:layout_height="wrap_content"/> 
  28.  
  29. </LinearLayout> 
  30.  
  31. <LinearLayoutandroid:orientationLinearLayoutandroid:orientation="horizontal" 
  32. android:layout_width="fill_parent" 
  33. android:layout_height="wrap_content" 
  34. android:gravity="center_horizontal"> 
  35.  
  36. <TextViewandroid:layout_widthTextViewandroid: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. <EditTextandroid:idEditTextandroid:id="@+id/password" 
  43. android:layout_width="200px" 
  44. android:layout_height="wrap_content" 
  45. android:password="true"/> 
  46. </LinearLayout> 
  47.  
  48. <LinearLayoutandroid:orientationLinearLayoutandroid: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> 
  61.  

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

準備工作差不多了,下面就可以寫代碼了。

 

責任編輯:佚名 來源: javaeye.com
相關推薦

2011-09-09 20:14:58

Android Wid

2011-09-08 13:11:07

Android Wid實例

2011-09-07 13:18:40

Android Wid

2011-02-28 13:04:27

RelativeLayAndroid Wid

2011-09-07 10:34:48

Android Wid

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 11:15:25

2011-09-08 10:04:07

Windows MobWidget

2011-09-07 13:00:36

2011-09-07 14:39:47

Android Wid設計

2011-05-03 15:13:23

BlackBerryWidget

2011-09-07 13:06:04

Android Wid

2011-09-07 14:20:42

Android Wid組件

2011-09-09 19:05:28

Widget

2010-07-13 09:08:27

Widget開發

2011-09-13 15:35:40

Widget

2011-09-07 16:28:46

QT WidgetQWidget

2010-05-13 10:45:38

點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 亚洲一区二区三区免费视频 | 一级黄色毛片a | 九九久久国产 | 成人影院网站ww555久久精品 | 精品久久久久久久久久久久 | 黄色片免费在线观看 | 国产美女精品 | 久久国产精品亚洲 | 鲁大师一区影视 | 日日操网站 | 日本午夜网 | 久久国产精品色av免费观看 | 欧美一区二区三区久久精品 | 日韩在线视频观看 | 91色网站| 亚洲综合久久精品 | 亚洲精品2区 | 久久夜夜| 精品美女在线观看 | 亚洲视频免费在线观看 | 精品久久久久久久久久久久久久 | 午夜寂寞影院列表 | 永久www成人看片 | 精品一区二区久久久久久久网精 | 国产视频二区 | 欧美激情久久久 | 欧美视频一区 | 成人二区 | 精品三级在线观看 | 欧美精品一区二区在线观看 | 91精品国产91久久久久游泳池 | 国产一区二区免费在线 | 亚洲精品无 | 二区中文 | 国产麻豆乱码精品一区二区三区 | 狠狠色狠狠色综合日日92 | 精品网站999www| 国产精品久久久久久久久久久久 | 久久婷婷色 | 在线色网| 中文字幕在线看 |