【问题标题】:How to partially update views in an app widget without rebuilding all the RemoteViews如何在不重建所有 RemoteView 的情况下部分更新应用小部件中的视图
【发布时间】:2012-08-02 05:54:56
【问题描述】:

我正在实现一个应用小部件,我希望能够更改小部件布局中单个视图的属性,而无需从头开始重建所有 RemoteViews,这涉及加载 XML 等,而这不是在某些情况下是必要的.. 有没有办法说“在当前小部件布局中由特定 ID 标识的视图上更新属性 X”?我已经看到partiallyUpdateAppWidget 类中有一个partiallyUpdateAppWidget 方法,但我不明白,也不能理解它是否是为此目的,也不能使用它。你能帮我或指出一个有用的方法吗?链接或示例?

【问题讨论】:

    标签: android android-layout android-widget remoteview


    【解决方案1】:

    是的,您可以在AppWidgetManager 类中使用partiallyUpdateAppWidget 方法。 例如,如果要更新小部件内的文本视图:

    AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
    rv = new RemoteViews(context.getPackageName(), R.layout.widgetlayout); 
    rv.setTextViewText(R.id.ofTextViewInWidgetLayoutXML, "Hello World");
    appWidgetManager.partiallyUpdateAppWidget(appWidgetIds, rv);
    

    参考: Just update a widget RemoteViews instead of completly creating a new one?

    【讨论】:

      猜你喜欢
      • 2022-01-25
      • 1970-01-01
      • 2011-08-17
      • 2014-05-28
      • 1970-01-01
      • 2021-08-18
      • 1970-01-01
      • 1970-01-01
      • 2020-10-19
      相关资源
      最近更新 更多