单击小部件时如何呈现吐司? [英] how to present a toast when a widget is clicked?

查看:17
本文介绍了单击小部件时如何呈现吐司?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要做一个简单的小部件,当点击它时会显示一个 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆