【问题标题】:Creating a Custom Expanded View in Code在代码中创建自定义展开视图
【发布时间】:2011-03-28 17:59:10
【问题描述】:

我想自定义通知区域,在右侧添加一个图标和几个按钮。 我在这里阅读了教程:http://developer.android.com/guide/topics/ui/notifiers/notifications.html

问题是我需要将此代码包含在一个库中,这是一个我想要分发以改进通知的 SDK。 (见http://hub.buzzbox.com/

是否可以在代码中编写所有 UI,而不需要 xml 来描述远程视图?这是因为资源不能包含在 SDK 中,所以我需要让我的 SDK 的用户将 xml 添加到他们的资源中并按名称引用所有资源......我想避免这种情况。 我已经完全用 Java 代码编写了 SDK 用户界面的其他部分,但是我在为 Remove View 执行相同操作时遇到了问题。

RemoteView 通常是这样创建的:

RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.custom_notification_layout);

我可以从我用 Java 代码创建的布局创建 RemoteView 吗? 还有其他解决方案吗?

【问题讨论】:

    标签: java android android-layout notifications


    【解决方案1】:

    我认为您可以使用自己的 Parcel 执行此操作,但查看代码,Parcel 仅存储主构造函数使用的包名称和布局(资源)ID。

    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(mPackage);
        dest.writeInt(mLayoutId);
        int count;
        if (mActions != null) {
            count = mActions.size();
        } else {
            count = 0;
        }
        dest.writeInt(count);
        for (int i=0; i<count; i++) {
            Action a = mActions.get(i);
            a.writeToParcel(dest, 0);
        }
    }
    

    我看不到这样做的方法,并且认为这可能是不可能的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多