2012-09-25 27 views
7

Creé un diseño de notificación personalizado, que tiene un botón en el que se puede hacer clic. Funciona muy bien en Android 3 (API nivel 11) o superior, pero no funciona en Android 2.3, el ContentIntent del Notification siempre se superpone a mi diseño y no puede ser reemplazado. No puedo clic en la vista, siempre clic en la notificación e iniciar elVista personalizada que se puede hacer clic en Notificación en Android 2.3 o inferior

Código para la visualización de la notificación y el diseño:

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; 

Diseño:

<?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> 

fácil. Pero no trabaje en Android 2.3 o inferior, ¿alguna idea?

Respuesta

11

Lo encontré, simplemente no es posible con Android 2.3 o inferior.
Clickably Notification botones funcionan solo en Android 3 o superior.

+1

¿Puede proporcionar un enlace al lugar donde está documentado? – Muzikant

+3

Lamentablemente no hay ningún documento, le pregunté a un ingeniero de Android a través de Google+. – Leandros

+0

@Leandros Después de escribir este código contentView.setOnClickPendingIntent (R.id.notButton, secondPendingIntent). ¿Cómo usaste tu botón? puedes dar un ejemplo, será una ayuda. –

Cuestiones relacionadas