2

私のアプリでは、5つのxmlファイルに対応する5つのアクティビティファイルを作成しました。最初のアクティビティでは、画像を選択できる別のアクティビティに移動するボタンを配置しました。選択した画像がアプリケーション全体のバックグラウンドにアタッチします。私に提案してください..

4

4 に答える 4

6

アプリケーションに共通の背景を 1 つ設定し、必要に応じて変更する方法を次に示します。

次のように独自のスタイルを作成します。

<style name="Background" parent="@android:style/Theme.NoTitleBar">
<item name="android:windowBackground">@android:color/black</item>
<item name="android:windowNoTitle">true</item>

マニフェストファイルで次のようにします:

<application  android:theme="@style/Background"/>

テーマ更新のグローバル メソッドは次のとおりです。各アクティビティで setContentView を実行する前に、アクティビティ コンテキストでこのメソッドを呼び出します。

public static void setTheme(Context context) {

    SharedPreferences pref=context.getSharedPreferences("preference",0);
    int position= pref.getInt("BackgroundPosition", 0);

    switch (position) {
    case 0:

        context.setTheme(R.style.Background0);

        break;

    case 1:

        context.setTheme(R.style.Background1);

        break;

    case 2:

        context.setTheme(R.style.Background2);

        break;

    case 3:
        context.setTheme(R.style.Background3);
        break;

    case 4:
        context.setTheme(R.style.Background4);
        break;
    }
}

ありがとう

于 2013-05-24T08:46:03.087 に答える
0

背景画像名を保存します (アプリが終了した後でも同じ画像が必要な場合は、SharedPreferences を使用できます
。すべてのアクティビティで動的に読み込みます。

LinearLayout ll = (LinearLayout) findViewById(R.id.blayout);
//This function will change background drawable, so place it where you want.
ll.setBackgroundDrawable(yourDrawableID);
于 2013-05-24T08:42:47.370 に答える