如何更改整个应用程序的背景图像

Dee*_*rma 1 android

在我的应用程序中,我创建了5个活动文件,对应于5个xml文件.现在,在第一个活动中,我放了一个导航到另一个活动的按钮,我可以从中选择一个图像.现在我想要选择的图像将是附在整个应用程序的后台.我该怎么办?请建议我..

Gau*_*ora 6

以下是为应用程序设置一个通用背景的方法,可根据您的要求进行修改.

按照以下方式制作自己的风格:

<style name="Background" parent="@android:style/Theme.NoTitleBar">
<item name="android:windowBackground">@android:color/black</item>
<item name="android:windowNoTitle">true</item>
Run Code Online (Sandbox Code Playgroud)

现在在清单文件中这样做:

<application  android:theme="@style/Background"/>
Run Code Online (Sandbox Code Playgroud)

这是主题更新的全局方法,在每个活动中的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;
    }
}
Run Code Online (Sandbox Code Playgroud)

谢谢