我想从我的小部件(AppWidgetProvider)的文本视图弹出窗口,我想在底部的“更新”和“关闭”2个按钮。我尝试使用AlertDialog,但它使小部件崩溃。
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setMessage("Sample text")
.setCancelable(false)
.setPositiveButton("Update", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
CallUpdate(context);
}
})
.setNegativeButton("Close", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
builder.show();
我希望能够使用跨转文本。
谢谢。
发布于 2012-04-27 21:29:45
App Widget可以支持以下布局类:
FrameLayout
LinearLayout
RelativeLayout
和以下窗口小部件类:
AnalogClock
Button
Chronometer
ImageButton
ImageView
ProgressBar
TextView
ViewFlipper
ListView
GridView
StackView
AdapterViewFlipper
因此,您不能从AppWidgetProvider
显示AlertDialog
。你可以在按钮点击时启动一个看起来像alertDialog的actvity。
要在主屏小部件上启动活动,请单击小部件,您可以看到以下帖子:
发布于 2012-04-27 21:14:24
您不能显示来自AppWidgetProvider
的AlertDialog
。您将需要通过startActivity()
创建一个Activity
并使用它。如果你愿意,你可以使用theme the activity to look like a dialog。
https://stackoverflow.com/questions/10351115
复制相似问题