久久中文视频-久久中文网-久久中文亚洲国产-久久中文字幕久久久久-亚洲狠狠成人综合网-亚洲狠狠婷婷综合久久久久


曙海教育集團論壇3G手機技術專區Android應用開發 → Widget開發入門-Android平臺


  共有8265人關注過本帖樹形打印

主題:Widget開發入門-Android平臺

美女呀,離線,留言給我吧!
wangxinxin
  1樓 個性首頁 | 博客 | 信息 | 搜索 | 郵箱 | 主頁 | UC


加好友 發短信
等級:青蜂俠 帖子:1393 積分:14038 威望:0 精華:0 注冊:2010-11-12 11:08:23
Widget開發入門-Android平臺  發帖心情 Post By:2010-12-3 12:53:07

本例是為了實現一個手機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子類。內容如下:
<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的相關信息,如該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:c>
</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圖片點擊可在新窗口打開查看rientation="vertical"
android:id="@+id/widget"
android:background="@drawable/title_a">
<LinearLayout android:layout_width="fill_parent"
android圖片點擊可在新窗口打開查看rientation="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圖片點擊可在新窗口打開查看rientation="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圖片點擊可在新窗口打開查看rientation="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圖片點擊可在新窗口打開查看rientation="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圖片點擊可在新窗口打開查看rientation="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圖片點擊可在新窗口打開查看rientation="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對象。

支持(0中立(0反對(0單帖管理 | 引用 | 回復 回到頂部

返回版面帖子列表

Widget開發入門-Android平臺








簽名
主站蜘蛛池模板: 美女很黄很黄免费 | 日本精品99 | 美女黄视频免费观看 | 久久a 热6| 黄色网址视频在线观看 | 国内精品久久久久久久影视麻豆 | 欧美精选欧美极品 | 在线观看日本亚洲一区 | 国产精品亚洲精品日韩已满 | 一级毛片一级毛片a毛片欧美 | 国产午夜精品不卡观看 | 香蕉久久a毛片 | 在线高清一级欧美精品 | 久久zyz| 一区二区三区精品国产欧美 | 日韩在线视频免费不卡一区 | 日本精品久久久久久久 | 男人天堂avav | 午夜视频一区二区 | 日本黄色美女网站 | 免费一级特黄特色黄大任片 | 国产一区二区久久久 | 91久久综合九色综合欧美98 | 日本在线亚州精品视频在线 | 亚洲一区二区三区在线网站 | 国产丝袜不卡一区二区 | 日韩三级小视频 | 亚洲国产精品成人综合久久久 | 91精品国产欧美一区二区 | 男人天堂中文字幕 | 欧美人与鲁交大毛片免费 | 亚洲an日韩专区在线 | 69国产成人综合久久精品91 | 国产精品热久久毛片 | 成人在线免费视频 | 91久久精品青青草原伊人 | 国产一区二区精品 | 91麻精品国产91久久久久 | 131的美女午夜爱爱爽爽视频 | 国产夫妇肉麻对白 | 日韩亚洲欧美综合一区二区三区 |