解决方案 »

  1.   

    给你的主layout 就是main.xml 最外层的layout 加个ID 然后获取它,然后setbackground 之类的
      

  2.   

    image1.setBackgroundResource(R.drawable.imageName);
      

  3.   

    //这里的parent就是主layout (默认也就是main.xml)最外层的layout 加的那个id 
    View parentView = findViewById(R.id.parent);
    Button button = (Button) findViewById(R.id.button1);
    button.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                parentView.setBackgroundResource(R.drawable.imageName);
                            }
                        });
      

  4.   

    注意的是,使用了样式,需要重新onCreate才能看到效果
      

  5.   

    setBackgroundResource(R.drawable.imageName);
      

  6.   

    这样都麻烦啊,有选择器的啊
    <?xml version="1.0"?>
    <!--
      Copyright (C) 2010 The Android Open Source Project  Licensed under the Apache License, Version 2.0 (the "License");
      you may not use this file except in compliance with the License.
      You may obtain a copy of the License at       http://www.apache.org/licenses/LICENSE-2.0  Unless required by applicable law or agreed to in writing, software
      distributed under the License is distributed on an "AS IS" BASIS,
      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      See the License for the specific language governing permissions and
      limitations under the License.
     --><selector xmlns:android="http://schemas.android.com/apk/res/android">
        <item android:state_pressed="true" android:drawable="@drawable/btn_speak_pressed" />
        <item android:state_selected="true" android:drawable="@drawable/btn_speak_selected" />
        <item android:drawable="@drawable/btn_speak_normal" />
    </selector>
      

  7.   

    其实更换背景图片的方法有不少,setBackground,setDrawable等等