android - 在状态栏中实现交互式通知(Android)

标签 android notifications statusbar

我想知道当用户点击状态栏中的通知时如何禁用突出显示效果,此外,我想允许用户直接与我通过 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/

相关文章:

java - 如何将EventBus设置到fragment中

android - 如何在 onSwipe 方法中更改键盘布局?

android - 将库添加到Android Studio项目:找不到名称为 'default'的配置

android - 向多个收件人发送短信的通知 - 不起作用

ios - 设置状态栏?

android - RecyclerView 2 Columns with CardView

ANDROID:如何从所有窗口顶部的通知或长按搜索按钮启动弹出对话框?

objective-c - 通知 ios,1 总是在图标旁边

swift - MacOS 在 StatusBar 上创建 ProgressBar

ios - MPMoviePlayerViewController观看后隐藏StatusBar并销毁Frame