顯示具有 App Widget 標籤的文章。 顯示所有文章
顯示具有 App Widget 標籤的文章。 顯示所有文章

2015年3月24日 星期二

Android的小工具(App Widget)

App Widget就是我們很常見到的Android桌面小工具,要製App Widget需要有一些步驟,這裡也一個有三個按鈕的小工具來做示範:

  1. 製作要給小工具用的Layout,程式碼如下所示

  2. appwidgetlayout.xml :
    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >
    
        <Button
            android:id="@+id/buttonToToast"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="按下後跳出訊息(Toast)" />
    
        <Button
            android:id="@+id/buttonToNotify"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="按下後發送通知(Notification)" />
    
        <Button
            android:id="@+id/buttonToOpenActivity"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="按下後前往另一個Activity" />
    
    </LinearLayout>