简体   繁体   English

更改背景图片 - Android

[英]Change background image - Android

I have main.xml file where is my background file:我有 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"

In another activity xml file there is the same "backgroundfile".在另一个活动 xml 文件中有相同的“背景文件”。

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:如果您问我们是否可以在所有活动的背景中使用相同的背景图像,那么可以,或者如果您想为所有活动使用单个 xml 文件作为背景文件,那么您可以在您的活动中使用这个 xml 文件 Z0F635D0E0F32E674F :

<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为此,您必须在运行时设置背景,并且背景的值将存储在共享首选项中,在所有活动的onCreate()中检查首选项背景值并设置相同

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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