在我的应用程序中,我创建了 5 个 Activity 文件,对应于 5 个 xml 文件。现在在第一个 Activity 中,我放置了一个按钮,可以导航到另一个 Activity ,从中我可以选择一个图像。现在我想要的图像是选择将附加在整个应用程序的后台。我必须做什么??请建议我..
最佳答案
这里是为你的应用程序设置一个通用背景的方法,根据你的要求修改它。
按照以下方式制作自己的样式:
<style name="Background" parent="@android:style/Theme.NoTitleBar">
<item name="android:windowBackground">@android:color/black</item>
<item name="android:windowNoTitle">true</item>
现在在 list 文件中这样做:
<application android:theme="@style/Background"/>
这里是主题更新的全局方法,在每个activity中setContentView之前用你的activity context调用这个方法
public static void setTheme(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;
}
}
谢谢
关于android - 如何更改整个应用程序的背景图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16730842/