我想知道当用户点击状态栏中的通知时如何禁用突出显示效果,此外,我想允许用户直接与我通过 notification 放置的 RemoteView 进行交互按下按钮。
我知道这是可以做到的,因为 HTC 的 Sense 在完成上述目标的通话过程中会收到持续通知。
如果您有任何想法,请告诉我,具体来说,如何为 RemoteView 中嵌套的 View 设置 OnClickListener?
最佳答案
我还没有尝试过,但它的工作方式应该与小部件使用 RemoteViews.setOnClickPendingIntent 的方式相同。禁用行的选择突出显示的一种方法可能是向外部布局元素添加单击 Intent,然后不对其执行任何操作。
例如,如果您的自定义布局如下所示。
<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 Intent ,
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 - 在状态栏中实现交互式通知(Android),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3091054/