我想知道当用户单击状态栏中的通知时如何禁用突出显示效果,此外,我想允许用户通过按下按钮直接与我放置在通知中的 RemoteView 交互.
我知道这是可以做到的,因为 HTC 的 Sense 在完成上述目标的通话过程中会持续发出通知。
如果您有任何想法,请告诉我,具体来说,如何为嵌套在 RemoteView 中的视图设置 OnClickListener?
我想知道当用户单击状态栏中的通知时如何禁用突出显示效果,此外,我想允许用户通过按下按钮直接与我放置在通知中的 RemoteView 交互.
我知道这是可以做到的,因为 HTC 的 Sense 在完成上述目标的通话过程中会持续发出通知。
如果您有任何想法,请告诉我,具体来说,如何为嵌套在 RemoteView 中的视图设置 OnClickListener?
我还没有尝试过,但它的工作方式应该与使用 RemoteViews.setOnClickPendingIntent 的小部件相同。禁用行的选择突出显示的一种方法可能是将单击意图添加到外部布局元素,然后不对其执行任何操作。
例如,如果您的自定义布局看起来像这样。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout_root"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:src="@drawable/button"/>
<TextView android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text="Some Text" />
</LinearLayout>
向 layout_root 添加 do_nothing 意图,
RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.yourlayout);
notification.contentView = contentView;
PendingIntent peClick = PendingIntent.getBroadcast(this, 0, new Intent("com.BUTTON_CLICK"), 0);
contentView.setOnClickPendingIntent(R.id.button, peClick);
PendingIntent peNothing = PendingIntent.getBroadcast(this, 0, new Intent("com.DO_NOTHING"), 0);
contentView.setOnClickPendingIntent(R.id.layout_root, peNothing);
顺便说一句,HTC 有能力以普通开发人员无法修改的方式修改 android,因此使用他们的东西作为可能的例子并不总是好的。
我仍在努力使一些类似的代码工作,但到目前为止我的观察是不同版本的 Android 处理不同的事情。在 Ice Cream Sandwich 上,对布局中的单个项目使用 setOnClickPendingIntent。但是,在早期版本的 Android 中,通知的 contentIntent 会首先触发,而按钮的 Intent 永远不会触发。可能有一些方法可以解决这个问题,但我还没有找到它。为通知的 contentintent 提供一个无所事事的意图似乎没有帮助,因为它仍然会抓住点击。