更改背景图片 - Android

时间:2011-08-16 08:56:24

标签: android background background-image

我有main.xml文件,其中是我的后台文件:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:background="@drawable/backgroundfile"

在另一个活动xml文件中,有相同的“backgroundfile”。

我想知道是否有可能为所有活动定义一个背景文件。我将创建一个新活动,用户将为整个应用程序选择背景。可能吗?你能给我一些线索吗?

谢谢你的帮助。 请原谅我的语言错误。

3 个答案:

答案 0 :(得分:2)

是的,有可能......

它是某种来源......

 public void onClick(View v){

    switch (v.getId()){
    case R.id.IVImage1:
        display.setImageResource(R.drawable.back_ah);
        toPhone = R.drawable.back_ah;
        break;
    case R.id.IVImage2:
        display.setImageResource(R.drawable.back_after_boom);
        toPhone = R.drawable.back_after_boom;
        break;
    case R.id.bSetWallpapper:
        Bitmap whatever = BitmapFactory.decodeStream(getResources().openRawResource(toPhone));
        try{
            getApplicationContext().setWallpaper(whatever);
        } catch(IOException e){
            e.printStackTrace();
        }
    }

答案 1 :(得分:1)

如果您要求我们可以在后台使用相同的背景图像进行所有活动,那么它是肯定的,或者如果您想将所有活动的单个xml文件用作后台文件,那么您可以在活动xml中使用此xml像这样的文件:

<include 
    android:id="@+id/your_id" 
    layout="@layout/your_xml_filetoset" />

答案 2 :(得分:1)

为此你必须在运行时设置背景,背景的值将存储在 onCreate()共享偏好中所有活动都会检查首选项背景值并设置相同的

相关问题