Manifest.xml檔案中的一些代碼作用:
<activity android:name=".LunchList" android:label="@string/app_name"><intent-filter><action android:name="android.intent.action.MAIN" /><category android:name="android.intent.category.LAUNCHER" /></intent-filter><intent-filter><action android:name="android.intent.action.SEARCH" /><category android:name="android.intent.category.DEFAULT" /></intent-filter><meta-data android:name="android.app.searchable" android:resource="@xml/searchable" /><meta-data android:name="android.app.default_searchable" android:value=".LunchList" /></activity>
在上面這段代碼中,
<intent-filter> <action android:name="android.intent.action.SEARCH" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter>
這個是註冊的隱式Intent的過濾器,第二行表示過濾帶有搜尋action的intent,第三行是必須要添加的(自訂的Activity如果要通過隱式intent啟動,則必須添加)
<meta-data android:name="android.app.searchable" android:resource="@xml/searchable" />
這個是在使用預設的搜尋方塊架是,給搜尋方塊設定的布局,第一行name是給定的,第二行resource就是你給自己的搜尋方塊設定的外觀布局,一般放在res/xml裡
<meta-data android:name="android.app.default_searchable" android:value=".LunchList" />
這個也是和搜尋相關,上面兩個是通過intent_filter過濾接收到intent,以及接收到intent之後顯示出來的搜尋方塊的布局,但那樣只是在你註冊了meta-data節點的activity裡面才能執行搜尋,如果想要在任意一個activity裡面都能啟動搜尋方塊架,就要加上這個,這個第一行也是給定的,第二行則用來指定是由哪一個activity響應並執行搜尋和顯示搜尋結果.
<receiver android:name=".AppWidget"android:label="@string/app_name"android:icon="@drawable/icon"><intent-filter><action android:name="android.appwidget.action.APPWIDGET_UPDATE"/><category android:name="android.intent.category.DEFAULT" /></intent-filter><meta-dataandroid:name="android.appwidget.provider"android:resource="@xml/widget_provider" /></receiver>
這段代碼中:註冊的是一個Widget,其中第二行是widget的標題,第三行是它的表徵圖,
<intent-filter><action android:name="android.appwidget.action.APPWIDGET_UPDATE"/><category android:name="android.intent.category.DEFAULT" /></intent-filter>
這個跟最上面的類似,就是註冊了intent的過濾器,過濾widget的更新action,第三行在上面解釋過了,這裡的更新actiong是放在隱式intent裡面的,所以要加上第三行
<meta-dataandroid:name="android.appwidget.provider"android:resource="@xml/widget_provider" />
這個則是對widget的參數配置,第二行是指定的,第三行就是我們自訂的widget參數,放在res/xml下,這裡的配置如下:res/xml/widget_provider.xml
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android" android:minWidth="300dip" android:minHeight="79dip" android:updatePeriodMillis="1800000" android:initialLayout="@layout/widget"/>
二三四行分別是寬高和更新頻率,第五行則是該widget的具體布局,布局方式與layout裡的其他布局方式一樣:res/layout/widget.xml
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="fill_parent"android:layout_height="fill_parent"android:background="@drawable/widget_frame"><TextView android:id="@+id/name"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_centerVertical="true"android:layout_alignParentLeft="true"android:layout_toLeftOf="@+id/next"android:textSize="10pt"android:textColor="#FFFFFFFF"/><ImageButton android:id="@+id/next"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_centerVertical="true"android:layout_alignParentRight="true"android:src="@drawable/ff"/></RelativeLayout>