2016-11-29 6 views
5

と黄色を使用することはできません。それは黄色の代わりにオリーブ色(ish)を示しています。は、私は通知オブジェクトを構築しながら</p> <p>私は<code>notification.setColor(Color.YELLOW);</code>を使用しているAndroidの7.xで黄色への通知小さなアイコンを設定し、問題をしたアンドロイドヌガー通知の小さなアイコン

notification.setColor(Color.argb(255,255,255,0));でも試してみましたが、運がなく、同じオリーブ(ish)色を示しています。

これは、Androidの7.xの中にどのように見えるかです

Android 7.1

これは、それが正しい色

Android 6.x

である、Androidの6.xの中にどのように見えるかですどちらの画像も、同じコードベースで、異なるAndroidデバイスを使用して同じ通知を表示します。

私はプッシュ通知を送受信するためにPushWooshを使用していますが、通知オブジェクトを作成するために使用しているコードは正確です。

public class NotificationFactory extends AbsNotificationFactory { 
@Override 
public Notification onGenerateNotification(PushData pushData) { 
    PushwooshUserdata pushwooshUserdata = GsonUtil.fromJson(pushData.getExtras().getString("u"), PushwooshUserdata.class); 

    //create notification builder 
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(getContext()); 
    notificationBuilder.setContentTitle("Header"); 
    notificationBuilder.setContentText("Message"); 

    //set small icon (usually app icon) 
    notificationBuilder.setSmallIcon(R.drawable.notification_icon); 
    notificationBuilder.setColor(Color.argb(255,255,255,0)); 

    //set ticket text 
    notificationBuilder.setTicker(getContentFromHtml(pushData.getTicker())); 

    //display notification now 
    notificationBuilder.setWhen(System.currentTimeMillis()); 

    //build the notification 
    final Notification notification = notificationBuilder.build(); 

    //add sound 
    addSound(notification, pushData.getSound()); 

    //add vibration 
    addVibration(notification, pushData.getVibration()); 

    //make it cancelable 
    addCancel(notification); 

    //all done! 
    return notification; 
} 

@Override 
public void onPushReceived(PushData pushData) { 
} 

@Override 
public void onPushHandle(Activity activity) { 
} 
} 
+0

通知の作成方法についてもう少し詳しく説明すると役に立ちます – Chisko

+0

ありがとうございます@Chisko、私は使用している正確なコードを含めるように質問を更新しました。 –

答えて

5

Androidは前景色と背景色の間の最小コントラスト比を確保している:あなたは.setColor(getResources().getColor(R.color.<YOUR_COLOR>))

ソースとして値を追加するには、NotificationBuilderで、その後colors.xmlで色を定義した場合

黄色(#ffff35)の前景と白い背景のコントラスト比はわずか1.07:1です。

オリーブの前景(#717d13)は、最低コントラスト比が4.5:1です。

これは、Androidのソースに関連するパッチである:https://android.googlesource.com/platform/frameworks/base.git/+/4ff3b120ff8a788e3afeb266d18caf072f0b8ffb%5E%21/

Iはhttp://webaim.org/resources/contrastchecker/を用いて上記コントラスト比を算出しました。

+0

@ eric-fikusありがとうございます。それがその背後にある理由です。 –

+0

私は、コントラストが白で4.5:1以下の色でテストしましたが、いつも私が選んだ色とは違う色になりました。新しい色のコントラストを計算すると、常に4.5を超えます。 あなたは私の一日を救った! –

0

は通知でそのUIコントロールアプリでActivityでも利用可能であり、ユーザーが通知をクリックすると、あなたは常にその活動を開始すべきであることを確認してください。これを行うには、setContentIntent()メソッドを使用します。 NotificationCompat.Builder#setColor(int)

関連する問題