我没有使用过的部件之前,但我所希望做的是建立一个非常简单的小工具我基本上要进行1:1的小工具,具有只是一个图标,只需设置为背景图像无文字没什么只是一个小图标,当图标为pressed我想打开一个活动。基本上,我想打第二个图标,就像在打开其他活动,而不是主要的一个小窗口形式的应用程序的抽屉。 任何帮助是极大AP preciated
Hi i've never worked with widgets before but what i'm looking to do is create a very simple widget i basically want to make a 1 by 1 widget that has just an icon, just an image set as the background no text nothing just a small icon and when the icon is pressed i want to open an activity. Basically i want to make a second icon like in the app drawer in a widget form that opens another activity rather than the main one. Any help is greatly appreciated
我的供应商最终看上去像这样大量的调查研究后,玩
My provider ended up looking like this after a lot of research and playing
public class WidgetProvider extends AppWidgetProvider {
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
final int N = appWidgetIds.length;
for (int i=0; i<N; i++) {
int appWidgetId = appWidgetIds[i];
Intent intent = new Intent(context, ClassToLaunchHere.class);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget);
views.setOnClickPendingIntent(R.id.widget, pendingIntent);
appWidgetManager.updateAppWidget(appWidgetId, views);
}
}
}