如果我有包含片段的活动,如何从片段里面改变父活动的背景颜色?
答案 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);
}
}