本文地址:http://blog.csdn.net/you_and_me12/article/details/8993239
2013-05-30
导语:学习一下AppWidget吧。
正文:本文只是在桌面上显示一个简单的插件。
Manifest.xml配置:
放置一个receiver, <meta-data>配置
<receiver android:name=".Test3_AppWidget" android:label="Test3" android:icon="@drawable/run_boy_2" > <intent-filter> <action android:name="android.appwidget.action.APPWIDGET_UPDATE"/> </intent-filter> <meta-data android:name="android.appwidget.provider" android:resource="@xml/test3_appwidget"/> </receiver>
插件显示配置:
区域大小、布局、刷新等等
<?xml version="1.0" encoding="UTF-8"?> <appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android" android:minWidth="72dp" android:minHeight="72dp" android:updatePeriodMillis="2000" android:initialLayout="@layout/test3_layout" > </appwidget-provider>
插件布局:
可使用FrameLayout/LinearLayout/RelativeLayout, 控件使用AnalogClock/Button/Chronometer/ImageButton/ProgressBar/TextView...
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="TEXT_1" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="TEXT_VIEW" /> </LinearLayout>
AppWidgetProvider即Receiver:
代码中什么都没写,需要时扩展吧
public class Test3_AppWidget extends AppWidgetProvider{ @Override public void onDeleted(Context context, int[] appWidgetIds) { super.onDeleted(context, appWidgetIds); System.out.println("Test3_AppWidget onDeleted"); } @Override public void onDisabled(Context context) { super.onDisabled(context); System.out.println("Test3_AppWidget onDisabled"); } @Override public void onEnabled(Context context) { super.onEnabled(context); System.out.println("Test3_AppWidget onEnabled"); } @Override public void onReceive(Context context, Intent intent) { super.onReceive(context, intent); System.out.println("Test3_AppWidget onReceive"); } @Override public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { super.onUpdate(context, appWidgetManager, appWidgetIds); System.out.println("Test3_AppWidget onUpdate"); } }
结尾: 1)坚持写写博客
2)继续学习安卓
3)我是IT程序猿