简体   繁体   中英

Change background image - Android

I have main.xml file where is my background file:

<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"

In another activity xml file there is the same "backgroundfile".

I'd like to know if there is possibility to define one background file to all activities. I am going to create new activity where user will choose background for the whole app. Is it possible? Can you give me some clues?

Thank you for help. Excuse me for language mistakes.

Yes, it's possible..

it's some sort of source..

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

if you are asking can we use same background image in background for all the activities then it is yes or if you want to use single xml file for all the activities as the background file then you can use this xml in your activity xml file like this:

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

for that you have to set background at runtime and the value of the background will stored in shared preference , in onCreate() of all activity check the preference background value and set the same

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM