The Desktop component app widget is a practical function of Android. Although the development process is not very difficult, there are many steps and a little trouble. The following key steps are summarized to facilitate future use. The project is packaged to facilitate future use. Create an android project and follow the steps below to create a simple app widget.
Step 1 create an appwidgetprovider subclass
public class SimpleWidget extends AppWidgetProvider{ @Override public void onUpdate(Context context,AppWidgetManager appWidgetManager, int[] appWidgetIds){ super.onUpdate(context, appWidgetManager, appWidgetIds); }}
Step 2 create the app widget layout file and setting file
Layout file Res/layout/simple_widget.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" > <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="TextView" /></LinearLayout>
Set file Res/XML/simple_widget.xml
(Initiallayout must match the layout file name)
<?xml version="1.0" encoding="utf-8"?><appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android" android:initialLayout="@layout/simple_widget" android:minWidth="72dp" android:minHeight="72dp" android:updatePeriodMillis="86400000" ></appwidget-provider>
Step 3 modify androidmanifest. xml
Add the following subnodes under the application node:
<receiver android:name="SimpleWidget" > <intent-filter> <action android:name="android.appwidget.action.APPWIDGET_UPDATE" /> </intent-filter> <meta-data android:name="android.appwidget.provider" android:resource="@xml/simple_widget" /></receiver>
Save all. In this step, you can start running. Demo:
Finally, we provide the packaged project source code package ,.