我有一个应用程序,在状态栏中显示笑脸“通知”图标的图片。 (这是应用程序的目的,只是为了显示笑脸)而且我想要这样做,这样你就可以更改设置中显示的图标。这是我的代码,首先显示图标的显示方式。如您所见,我从drawable文件夹加载它。
@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>
如果你能告诉我如何添加像一个复选框来加载一个非常棒的不同图标(图片)。非常感谢你。
答案 0 :(得分:0)
我所做的是忘记复选框并在首选项中手动创建一个按钮。
的preferences.xml
<Preference android:title="Button Title"
android:key=" button_id"
android:summary="Button Description"/>
然后转到您的首选项类,并在onCreate()方法上添加
Preference button = (Preference)findPreference("button_id");
button.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference arg0) {
//Add what you want it to do here
return true;
}
});
以防万一将来遇到同样的问题(: