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

前端之家收集整理的这篇文章主要介绍了Android 2.3或更低版本的通知中的可点击自定义视图前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
@H_502_0@
我创建了一个自定义通知布局,它有一个可点击的按钮.到目前为止在 Android 3(API Level 11)或更高版本上工作得很好,但是在Android 2.3上不起作用,Notification中的ContentIntent总是覆盖我的布局而无法覆盖.
我无法点击视图,我总是点击通知并启动

显示通知和布局的代码

  1. Builder builder = new NotificationCompat.Builder(getApplicationContext());
  2.  
  3. RemoteViews contentView = new RemoteViews(getPackageName(),R.layout.notification_layout);
  4. contentView.setImageViewResource(R.id.notImage,R.drawable.stat_icon);
  5. contentView.setTextViewText(R.id.notTitle,"Title");
  6. contentView.setTextViewText(R.id.notText,"Text");
  7. contentView.setOnClickPendingIntent(R.id.notButton,secondPendingIntent);
  8. contentView.setOnClickPendingIntent(R.id.notContentLayout,pendingIntent);
  9.  
  10. builder
  11. .setContentTitle("Title")
  12. .setContentText("Text")
  13. .setSmallIcon(R.drawable.stat_icon)
  14. .setOngoing(true)
  15. .setWhen(0)
  16. .setTicker("Ticket")
  17. .setContent(contentView)
  18. .setContentIntent(contentIntent); //this intent override my contentView.setOnClickPendintIntent. I can't click the view.
  19.  
  20. not = builder.build();
  21.  
  22. not.contentView = contentView;

布局:

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:id="@+id/layout"
  4. android:layout_width="fill_parent"
  5. android:layout_height="fill_parent"
  6. android:padding="10dp" >
  7.  
  8. <RelativeLayout
  9. android:id="@+id/notContentLayout"
  10. android:layout_width="wrap_content"
  11. android:layout_height="match_parent"
  12. android:layout_alignParentLeft="true"
  13. android:layout_toLeftOf="@+id/notButton" >
  14.  
  15. <ImageView
  16. android:id="@+id/notImage"
  17. android:layout_width="wrap_content"
  18. android:layout_height="fill_parent"
  19. android:layout_alignParentLeft="true"
  20. android:layout_marginLeft="8dp"
  21. android:layout_marginRight="23dp"
  22. android:contentDescription="@string/image_desc" />
  23.  
  24. <TextView
  25. android:id="@+id/notTitle"
  26. style="@style/NotificationTitle"
  27. android:layout_width="wrap_content"
  28. android:layout_height="wrap_content"
  29. android:layout_toRightOf="@id/notImage" />
  30.  
  31. <TextView
  32. android:id="@+id/notText"
  33. style="@style/NotificationText"
  34. android:layout_width="wrap_content"
  35. android:layout_height="wrap_content"
  36. android:layout_below="@id/notTitle"
  37. android:layout_toRightOf="@id/notImage" />
  38. </RelativeLayout>
  39.  
  40. <ImageButton
  41. android:id="@+id/notButton"
  42. android:layout_width="wrap_content"
  43. android:layout_height="wrap_content"
  44. android:layout_alignParentRight="true"
  45. android:layout_centerVertical="true"
  46. android:background="@color/transparent"
  47. android:contentDescription="@string/image_desc"
  48. android:padding="10dp"
  49. android:src="@android:drawable/ic_media_pause" />
  50.  
  51. </RelativeLayout>

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

解决方法

我发现它,Android 2.3或更低版本是不可能的. 可点击通知按钮仅适用于Android 3或更高版本.

猜你在找的Android相关文章