相关疑难解决方法(0)

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

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

显示通知和布局的代码:

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;
Run Code Online (Sandbox Code Playgroud)

布局:

<?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" …
Run Code Online (Sandbox Code Playgroud)

layout notifications android

7
推荐指数
1
解决办法
2812
查看次数

标签 统计

android ×1

layout ×1

notifications ×1