2012-09-25 15 views
7

クリック可能なボタンを持つカスタム通知レイアウトを作成しました。 Android 3(APIレベル11)以上では正常に動作しますが、Android 2.3では動作しません。NotificationContentIntentは常に自分のレイアウトをオーバーレイしてオーバーライドできません。 私はビューをクリックすることはできません、私はいつもの通知をクリックして、通知やレイアウトを表示するためのAndroid 2.3以降の通知でクリック可能なカスタム表示

コードを起動します。

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以下では動作しません。

答えて

11

私はそれを見つけました。それはAndroid 2.3以下では不可能です。
Clickably NotificationボタンはAndroid 3以降でのみ動作します。

+1

文書化された場所へのリンクを提供できますか? – Muzikant

+3

悲しいことに、ドキュメントはありません。私はAndroidエンジニアにGoogle+経由で尋ねました。 – Leandros

+0

@Leandrosこのコードを記述した後、contentView.setOnClickPendingIntent(R.id.notButton、secondPendingIntent)。どのようにボタンを使いましたか?あなたはそれが助けになる例を挙げることができますか? –

関連する問題