如何在android中创建Widget?

时间:2014-01-12 17:53:38

标签: android widget

我想创建一个小部件来显示所有在线用户真的很容易在Android应用程序中执行此操作 但我想创建一个小部件

有没有办法做到这一点?

enter image description here

public class WatchWidget extends AppWidgetProvider {

    @Override
    public void onUpdate(Context context, AppWidgetManager appWidgetManager,
            int[] appWidgetIds) {
        // TODO Auto-generated method stub
        super.onUpdate(context, appWidgetManager, appWidgetIds);
        RemoteViews remoteViews;
        ComponentName watchWidget;
        java.text.DateFormat format = SimpleDateFormat.getTimeInstance(
                SimpleDateFormat.MEDIUM, Locale.getDefault());

        remoteViews = new RemoteViews(context.getPackageName(), R.layout.activity_main);
        watchWidget = new ComponentName(context, WatchWidget.class);
        remoteViews.setTextViewText(R.id.textView,
                "Time = " + format.format(new Date()));
        appWidgetManager.updateAppWidget(watchWidget, remoteViews);
    }

}

0 个答案:

没有答案