The basic steps to create a widget are:
1. Write a class inheritance Appwidgetprovider, so you can see that the widget is actually a broadcast, so to register the broadcast in the manifest file
2. Configure in the manifest file
<receiver android:name= "Com.example.mobilesafe.receiver.MyWidget" >
<intent-filter>
< android:name= "Android.appwidget.action.APPWIDGET_UPDATE"/>
</intent-filter>
<meta-data
Android:name= "Android.appwidget.provider"
Android:resource= "@xml/process_widget_provider"/>
</receiver>
2.1 in which receiver name is a subclass of Appwidgetprovider,
Action in the name intent filter actions, do not change;
Finally, create the XML folder under the Res folder and create the Process_widget_provider.xml file in the folder
3.process_widget_provider.xml file
<?xml version= "1.0" encoding= "Utf-8"?>
<appwidget-provider xmlns:android= "Http://schemas.android.com/apk/res/android"
android:initiallayout= "@layout/process_widget"
android:minheight= "100dip"
Android:minwidth= "300dip"
android:updateperiodmillis= "0"/>
Android:initiallayout the display layout file for the widget
Android:minheight the display height of the widget
Android:minwidth the display width of the widget
Android:updateperiodmillis the time to automatically update its interface content
4. layout file Android:initiallayout
<linearlayout xmlns:android= "Http://schemas.android.com/apk/res/android"
Android:layout_width= "Match_parent"
android:layout_height= "Wrap_content"
android:gravity= "Center_vertical" >
<textview
Android:id= "@+id/tv"
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
android:layout_marginleft= "10.0dip"
android:text= "Hello widget"/>
</LinearLayout>
Android Weiget Control First Solution