Objective
Hello everyone, to bring you Android开发工程师文集-1 小时学会Widget小组件开发
an overview, I hope you like
Learn to use Widgets (widget)
Widgets Widget is very convenient, very quick, can be personalized, their own customization, related features, you can update the latest content in real time.
- Widget layout, widget configuration, appwidgetprovider and configuration Activity
- Android Widgets
- XML layout type: Appwidget Provider
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android" //引用的布局文件 android:initialLayout="@layout/widget" android:minHeight="50dp" android:minWidth="100dp" //设置更新时间 android:updatePerioMillis="66666666"></appwidget-provide>
public class WidgetProvider extends AppWidgetProvider { @Override public void onDeleted(Context context,int[] appWidgetIds){ super.onDeleted(context,appWidgetIds);} @Override public void onDisabled(Context context){ super.onDisabled(context); } @Override public void onEnabled(Context context){ super.onEnabled(context); } @Override public void onReceive(Context context,Intent intent){ super.onReceive(context,intent); } @Override public void onUpdate(Context context,AppWidgetManager appWidgetManager,int[] appWidgetIds){ super.onUpdate(context,appWidgetManager,appWidgetIds);}}
//TimerService extends ServiceTimer timer=new Timer();timer.shedule(new TimerTask(){ @Override public void run(){ updateTime(); } },0,1000);}//onDestroypublic void onDestroy(){ super.onDestroy(); timer=null;}//updateTime();private void updateTime(){ String time = simpletime.format(new Date());}
Widgets are desktop widgets, and with widgets, we can do a variety of things directly on the desktop.
Widget use
- Androidmanifest declaration in Appwidget
- Appwidget configuration file defined in XML
- Define widget layout files in layout
- Create class Inheritance Appwidgetprovider class
//清单文件中<meta-data android:name="android.appwidget.provider" android:resource="@layout/widget_setting"/>
//onUpdate()重点@Overridepublic void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { super.onUpdate(context, appWidgetManager, appWidgetIds); RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.layout_widget); //Intent intent = new Intent(); Intent intent = new Intent(); intent.setClass(context, TestWidget.class);
//清单文件 <intent-filter> <action android:name="android.appwidget.action.APPWIDGET_UPDATE" /> </intent-filter> <meta-data android:name="android.appwidget.provider" android:resource="@xml/widget_provider"/>
Summarize
- This article is about Android development engineer Anthology-1 Hours Learning widget widgets Development, if you have a better understanding, welcome to communicate
- Positioning: Sharing
Android
& Java
knowledge points, interested to continue to follow
Android Development Engineer Anthology-1-hour learning widget widgets Development