(android) 添加一个小部件
好吧,我创建了这个小部件,
public class Widget extends AppWidgetProvider{
private SimpleDateFormat formatter = new SimpleDateFormat (
"EEEEEEEEE\nd MMM yyyy");
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
String now = formatter.format(new Date());
RemoteViews updateViews = new RemoteViews (
context.getPackageName() , R.layout.widget );
updateViews.setTextViewText(R.id.text, now);
appWidgetManager.updateAppWidget(appWidgetIds, updateViews);
super.onUpdate(context, appWidgetManager, appWidgetIds);
}
}
它只显示日期,但我不知道如何将此类添加到我的主程序中,并最终在主屏幕上显示该小部件。你能帮助我吗?
Well, i have created this widget
public class Widget extends AppWidgetProvider{
private SimpleDateFormat formatter = new SimpleDateFormat (
"EEEEEEEEE\nd MMM yyyy");
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
String now = formatter.format(new Date());
RemoteViews updateViews = new RemoteViews (
context.getPackageName() , R.layout.widget );
updateViews.setTextViewText(R.id.text, now);
appWidgetManager.updateAppWidget(appWidgetIds, updateViews);
super.onUpdate(context, appWidgetManager, appWidgetIds);
}
}
It just shows the date, but i dont know how to add this class to my main program and finally show the widget on the home screen. Can you help me?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是一个链接,指向类似的小部件,该小部件为 XMas.you 提供了剩余的天数可以根据您的需要进行定制。
当用户从小部件列表中选择它时,小部件就会显示。所以我认为,你只需要担心哪个小部件将显示的数据。其余的将由用户决定是否将该小部件保留在主屏幕上。
Here is a link to similar widget which gives days left to XMas.you can customize it to your need.
And widget would be displayed when user choose it from widget lists. So i think,you just have to worry for the data which widget would display.rest would be upto user whether to keep that widget on homescreen or not.
Widget 基本上是一个广播接收器。如果您已经有一个应用程序,请将此小部件(广播接收器)添加到其清单文件中。
这是一个链接 - http://developer.android.com/guide/topics/ appwidgets/index.html
Widget is basically a broadcast receiver. if you already have an application, then add this widget(broadcast receiver) to its manifest file.
Here is a link - http://developer.android.com/guide/topics/appwidgets/index.html
剩余天数 Widget ## public class WidgetProvider extends AppWidgetProvider {
}
https://play.google.com/store/apps/details ?id=com.Free.daysleft
Days Left Widget ## public class WidgetProvider extends AppWidgetProvider {
}
https://play.google.com/store/apps/details?id=com.Free.daysleft