2
我想在每个通知中添加一个按钮...并且用户可以单击该按钮以删除单个通知,我看到很多人说只是参考“创建自定义展开视图”并使用RemoteViews,但是可以修改官方代码并让按钮工作吗? 我曾在“status_bar_latest_event_context.xml”按钮添加使用的ImageButton如何在Android通知中添加按钮
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingTop="3dp"
>
<!--com.android.server.status.AnimatedImageView android:id="@+id/icon" -->
<ImageView android:id="@+id/icon"
android:layout_width="25dp"
android:layout_height="25dp"
android:scaleType="fitCenter"
android:src="@drawable/arrow_down_float"/>
<TextView android:id="@+id/title"
android:textAppearance="@style/TextAppearance.StatusBar.EventContent.Title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:singleLine="true"
android:ellipsize="marquee"
android:fadingEdge="horizontal"
android:paddingLeft="4dp"
/>
<ImageButton android:id="@+id/imgbtn_del"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/btn_close"/>
</LinearLayout>
,它会显示在每个通知图像按钮,但我不知道如何让按钮工作。
在StatusBarService.java,我们可以发现
// bind the click event to the content area
ViewGroup content = (ViewGroup)row.findViewById(R.id.content);
content.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS);
content.setOnFocusChangeListener(mFocusChangeListener);
PendingIntent contentIntent = n.contentIntent;
if (contentIntent != null) {
content.setOnClickListener(new Launcher(contentIntent, notification.pkg,
notification.tag, notification.id));
}
它的单击事件绑定到内容区域。所以我不能点击按钮。 我不知道如何修改源代码以及如何设置OnClick函数..
请帮忙... 非常感谢!