我有一个应用程序,它在状态栏中显示笑脸“通知”图标的图片。(这是应用程序的目的,只是为了显示那个笑脸)我想做它,以便您可以更改设置中显示的图标。这是我首先如何显示图标的代码。如您所见,我从可绘制文件夹中加载它。
@Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//Smiley Notification Starts
NotificationManager nm=(NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification=new Notification(R.drawable.smiley_notification, "Smiley", System.currentTimeMillis());
Context context=MainActivity.this;
CharSequence title="Smiley Title";
CharSequence detail="Touch for more options";
Intent intent=new Intent(context,MainActivity.class);
PendingIntent pending=PendingIntent.getActivity(context, 0, intent, 0);
notification.setLatestEventInfo(context, title, detail, pending);
nm.notify(0, notification);
//Smiley Notification Ends
这是我的设置 xml 文件。
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory android:title="Additional Information" android:summary="More">
<PreferenceScreen android:title="My Name" android:summary="Smiley Notification Developer">
<intent android:action="android.intent.action.VIEW" android:data="http://instagram.com/AccountName" />
</PreferenceScreen>
<Preference
android:title="Requests/Support"
android:summary="Click here to email me">
<intent
android:action="android.intent.action.VIEW"
android:data="mailto:email@email.com?subject=Support*Smiley Lite">
<extra android:name="android.intent.extra.TEXT" android:value="Enter your request or problem here with a brief description." />
</intent>
</Preference>
<PreferenceScreen android:title="More apps by provider" android:summary="Click here">
<intent android:action="android.intent.action.VIEW" android:data="http://website.com" />
</PreferenceScreen>
</PreferenceCategory>
</PreferenceScreen>
如果你能告诉我如何添加一个复选框来加载不同的图标(图片),那就太好了。非常感谢。