之前看别人说用android studio ,而我还是用着ecilipse不以为然,试了一次,感觉还不如ecilipse好用,后来还是一直用的ecilipse,知道最近用起了android studio才发现真的很强大,支持各种功能,扯远了,在ecilipse中制作桌面插件,又要配置这个又要配置那个,而在android studio中真的是一键搞定,没有比这个更好的了。下面来看看android studio生成的一些关于AppWidgets的一些文件。
我们来按照一般的设计流程看下代码:
1.新建AppWidgetProvider继承类:MyAppWidget
public class MyAppWidget extends AppWidgetProvider { //第一次加载时调用,是个静态函数,很明显 static void updateAppWidget(Context context, AppWidgetManager appWidgetManager, int appWidgetId) { CharSequence widgetText = context.getString(R.string.appwidget_text); // 加载布局文件生成RemoteViews,即要显示的View RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.my_app_widget); views.setTextViewText(R.id.appwidget_text, widgetText); // Instruct the widget manager to update the widget appWidgetManager.updateAppWidget(appWidgetId, views); } //桌面插件内容更新函数,生命周期内,每隔固定时间更新一次,调用一次 @Override public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { // There may be multiple widgets active, so update all of them for (int appWidgetId : appWi