【问题标题】:How to delete widget from activity?如何从活动中删除小部件?
【发布时间】:2011-06-29 22:37:25
【问题描述】:

可以从主要活动中删除小部件吗?我正在写小记事本,当一些笔记被删除时,我想用这个笔记删除小部件。

编辑:

当我做这样的事情时:

Context context = getApplicationContext(); 
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context); 
RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget);
ComponentName thisWidget = new ComponentName(context, Widget.class);
remoteViews.removeAllViews(R.id.widgetLayout); 
appWidgetManager.updateAppWidget(thisWidget, remoteViews);

小部件不可见(因为它没有任何视图),但我仍然可以点击它等。

我想在某个 Activity 中从主屏幕删除小部件。

【问题讨论】:

    标签: android android-activity android-widget widget


    【解决方案1】:

    ViewGroup 有几个removeView*(View) 方法。或者,您可以调用setVisibility(View.GONE) 使小部件从屏幕上消失而不实际删除它。

    巴里

    【讨论】:

      猜你喜欢
      • 2013-07-14
      • 1970-01-01
      • 2013-02-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-08
      • 2014-02-08
      • 1970-01-01
      相关资源
      最近更新 更多