0

ステータスバーにスマイリーの「通知」アイコンの画像を表示するアプリがあります。(それがアプリの目的です。そのスマイリーを表示するだけです)そして、設定で表示されるアイコンを変更できるようにしたいと考えています。最初にアイコンがどのように表示されるかについての私のコードは次のとおりです。ご覧のとおり、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>

別のアイコン(画像)をロードするためにチェックボックスのように追加する方法を教えていただければ、それは素晴らしいことです。どうもありがとうございました。

4

1 に答える 1

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;
                }
            });

誰かが将来同じ問題を経験する場合に備えて (:

于 2013-09-05T22:24:21.483 に答える