如何从里面的片段更改活动背景

时间:2014-05-03 10:16:55

标签: android background android-activity

如果我有包含片段的活动,如何从片段里面改变父活动的背景颜色?

1 个答案:

答案 0 :(得分:0)

像这样使用:

class Main extends FragmentActivity {
    public ImageView imageView;

    @Override
    protected void onCreate(Bundle arg0) {

        super.onCreate(arg0);
        setContentView(R.layout.main);
        imageView = (ImageView)findViewById(R.id.ivMain);
    }
}

class Demo extends Fragment {
    Main main;

    public void onAttach(Activity activity) {
        main = (Main) activity;
    };

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        main.imageView.setBackgroundColor(color);
        return super.onCreateView(inflater, container, savedInstanceState);
    }

}