栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

Android中的可点击小部件

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Android中的可点击小部件

首先,添加带有常量的静态变量。

public static String YOUR_AWESOME_ACTION = "YourAwesomeAction";

然后,你需要先将动作添加到意图中,然后再将意图添加到未决意图中:

Intent intent = new Intent(context, widget.class);intent.setAction(YOUR_AWESOME_ACTION);

(其中widget.class是你的AppWidgetProvider的类,当前的类)

然后,你需要使用getBroadcast创建一个PendingIntent

PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intent, 0);

在窗口小部件中为可点击的视图设置onClickPendingIntent

remoteView.setonClickPendingIntent(R.id.widgetframeLayout, pendingIntent);

接下来,在同一类中重写onReceive方法:

@Overridepublic void onReceive(Context context, Intent intent) { super.onReceive(context, intent);

然后通过在onReceive方法中查询为你的操作返回的意图来响应你的按钮按下:

if (intent.getAction().equals(YOUR_AWESOME_ACTION)) {   //do some really cool stuff here}

那应该做到的!



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/367722.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号