android - Android 2.3 或更低版本通知中的可点击自定义 View

标签 android layout notifications

我创建了一个自定义通知布局,它有一个可点击的按钮。目前在 Android 3(API 级别 11)或更高版本上运行良好,但不适用于 Android 2.3,Notification 中的 ContentIntent 始终覆盖我的布局并且不能不要被覆盖。 我无法点击 View ,我总是点击通知并启动

显示通知和布局的代码:

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;

布局:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/layout"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:padding="10dp" >

    <RelativeLayout
        android:id="@+id/notContentLayout"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_alignParentLeft="true"
        android:layout_toLeftOf="@+id/notButton" >

        <ImageView
            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" />

        <TextView
            android:id="@+id/notTitle"
            style="@style/NotificationTitle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_toRightOf="@id/notImage" />

        <TextView
            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" />
    </RelativeLayout>

    <ImageButton
        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" />

</RelativeLayout>

简单。但不适用于 Android 2.3 或更低版本,有什么想法吗?

最佳答案

我找到了,它在 Android 2.3 或更低版本上是不可能的。
可点击的 Notification 按钮仅适用于 Android 3 或更高版本。

关于android - Android 2.3 或更低版本通知中的可点击自定义 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12586938/

相关文章:

android - 启用通知访问时未调用应用程序 onCreate

Android SQLite 多表数据库开发

java - 拖放到相对布局中

网页布局的CSS参数

swift - xcode 8 自动布局 uiimageview 问题

Android:如何创建 "Ongoing"通知?

android - 是否使用 LoaderManager 进行详细查看?

android - 设置自定义背景覆盖 ListView 自定义

CSS - 填充可用的剩余空间

iOS 警报行为与相同的 APNS 消息不一致