单击小部件时如何呈现吐司? [英] how to present a toast when a widget is clicked?
问题描述
我需要做一个简单的小部件,当点击它时会显示一个 Toast.我的问题是我找不到如何获取或创建oncreate"操作.我看到了打开 Web 浏览器的未决意图的示例.但是我如何简单地创建这个: Toast.makeText(context, "activated", Toast.LENGTH_LONG).show();
并在每次用户点击小部件时实现它?为了清楚起见,我的意思是手机启动器上的一个小部件.不是常规的按钮"小部件等...
I need to do a simple widget that presents a Toast when clicking on it.
My problem is that I cant find how to get or create an "oncreate" action. i see the examples with the pending intent that opens the web browser. But how do i simply create this: Toast.makeText(context, "activated", Toast.LENGTH_LONG).show();
and make it happen every time a user clicks on the widget?
just to be clear, I mean a widget on the launcher of the phone. not a regular "button" widget etc...
public class Widget extends AppWidgetProvider {
NotificationManager mNotificationManager;
Notification notification;
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
super.onUpdate(context, appWidgetManager, appWidgetIds);
appWidgetManager.updateAppWidget(appWidgetIds, view);
}
}
谢谢!
推荐答案
只需在widget的中调用
Toast.makeText(context, "activated", Toast.LENGTH_LONG).show();
View.OnClickListener
如果您使用 AppWidgetProvider
请检查 this 和这个帖子
If you use AppWidgetProvider
so check this and this one posts
这篇关于单击小部件时如何呈现吐司?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!