在我当前版本的应用程序中,我想实现一个通知系统。
为此,我已经创建了两个首选项:
<ListPreference
android:title="@string/notificationColor"
android:summary="@string/notificationColorSummary"
android:key="notificationColor"
android:entries="@array/notificationColor"
android:entryValues="@array/notificationColor"/>
该数组包含以下内容:
<string-array name="notificationColor">
<item>Default</item>
<item>Yellow</item>
</string-array>
要发送测试通知,这是偏好:
<Preference
android:title="@string/notificationTest"
android:key="notification_test"
android:summary="@string/notificationTestSummary"/>
现在来到“真正的”代码。有了这个,我创建了通知:
Preference notificationTest = (Preference)findPreference("notification_test");
notificationTest.setOnPreferenceClickListener(newPreference.OnPreferenceClickListener() {
public boolean onPreferenceClick(Preference preference) {
mBuilder.setSmallIcon(R.drawable.ic_school_white_36dp);
mBuilder.setContentTitle("Timetable");
mBuilder.setContentText("Hi, this is a test notification from your Timetable App!");
//Set the normal Light
mBuilder.setLights(0xff0000ff, 3000, 100);
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
// notificationID allows you to update the notification later on.
mNotificationManager.notify(001, mBuilder.build());
return true;
}
});
这是我的OnPreferenceChanged:
final ListPreference notificationColor = (ListPreference) findPreference("notificationColor");
notificationColor.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
public boolean onPreferenceChange(Preference preference, Object newValue) {
if(notificationColor.getValue() == "Yellow") {
//Overwrite the Color from the OnPreferenceClickListener (Blue) with Yellow
}
return false;
}
});
我的代码中已经提到了我想要的内容。基本上,我设置了一个普通的颜色,如果用户改变了正常的颜色,用选择的颜色覆盖OnPreferenceClicked。
或者有没有办法为竞争应用程序提供默认的通知颜色,然后改变它?
答案 0 :(得分:0)
要更改通知的颜色,您需要定义通知的自定义视图。然后,您可以轻松控制背景和文本颜色。