【问题标题】:Android Widget PopupAndroid 小部件弹出窗口
【发布时间】:2012-04-27 13:02:57
【问题描述】:

我想从我的小部件 (AppWidgetProvider) 中创建一个带有 textview 的弹出窗口,我想要底部的“更新”和“关闭”中的 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();

我希望能够使用跨区文本。

谢谢。

【问题讨论】:

  • 它是如何崩溃的?我看不出你那里有什么明显的问题,但我们当然不能自己运行它......

标签: android android-widget popupwindow android-alertdialog


【解决方案1】:

App Widget 可以支持以下布局类:

FrameLayout
LinearLayout
RelativeLayout

还有以下小部件类:

AnalogClock
Button
Chronometer
ImageButton
ImageView
ProgressBar
TextView
ViewFlipper
ListView
GridView
StackView
AdapterViewFlipper

所以你不能从AppWidgetProvider 显示AlertDialog。您可以在按钮单击时启动一个类似于 alertDialog 的活动。

对于在主屏幕小部件上启动活动,单击您可以看到这些帖子:

Launching activity from widget

How to launch activity from android home screen widget

【讨论】:

    【解决方案2】:

    您无法显示来自AppWidgetProviderAlertDialog。您将需要创建一个Activity 并通过startActivity() 使用它。如果您愿意,可以theme the activity to look like a dialog

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-03-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-02-02
      相关资源
      最近更新 更多