android自定义通知大视图,Android 2.3或更低版本的通知中的可点击自定义视图

我创建了一个自定义通知布局,它有一个可点击的按钮.到目前为止在Android 3(API Level 11)或更高版本上工作得很好,但是在Android 2.3上不起作用,ContentIntent从Notification总是覆盖我的布局并且无法覆盖.我无法点击视图,我总是点击通知并启动

显示通知和布局的代码:

Builder builder = new NotificationCompat.Builder(getApplicationContext());

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

contentView.setImageViewResource(R.id.notImage, R.drawable.stat_icon);

contentView.setTextViewText(R.id.notTitle, "Title");

contentView.setTextViewText(R.id.notText, "Text");

contentView.setOnClickPendingIntent(R.id.notButton, secondPendingIntent);

contentView.setOnClickPendingIntent(R.id.notContentLayout, pendingIntent);

builder

.setContentTitle("Title")

.setContentText("Text")

.setSmallIcon(R.drawable.stat_icon)

.setOngoing(true)

.setWhen(0)

.setTicker("Ticket")

.setContent(contentView)

.setContentIntent(contentIntent); //this intent override my contentView.setOnClickPendintIntent. I can't click the view.

not = builder.build();

not.contentView = contentView;

布局:

android:id="@+id/layout"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:padding="10dp" >

android:id="@+id/notContentLayout"

android:layout_width="wrap_content"

android:layout_height="match_parent"

android:layout_alignParentLeft="true"

android:layout_toLeftOf="@+id/notButton" >

android:id="@+id/notImage"

android:layout_width="wrap_content"

android:layout_height="fill_parent"

android:layout_alignParentLeft="true"

android:layout_marginLeft="8dp"

android:layout_marginRight="23dp"

android:contentDescription="@string/image_desc" />

android:id="@+id/notTitle"

style="@style/NotificationTitle"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_toRightOf="@id/notImage" />

android:id="@+id/notText"

style="@style/NotificationText"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_below="@id/notTitle"

android:layout_toRightOf="@id/notImage" />

android:id="@+id/notButton"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignParentRight="true"

android:layout_centerVertical="true"

android:background="@color/transparent"

android:contentDescription="@string/image_desc"

android:padding="10dp"

android:src="@android:drawable/ic_media_pause" />

简单.但是不要在Android 2.3或更低版本上工作,任何想法?

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值