I've a LinearLayout with a default background and I change the background by click on a button. By orientation the screen the background is reset to default background. I don't know why.
private Drawable backgroundImage;
public void InitializeUI() {
parentLayout = (LinearLayout) findViewById(R.id.fragment_parent);
if(backgroundImage != null) {
parentLayout.setBackground(backgroundImage);
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
InitializeUI();
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
setContentView(R.layout.activity_main);
InitializeUI();
}
Changing the background with
Drawable d = new BitmapDrawable(getResources(), selectedBitmap);
this.backgroundImage = d;
parentLayout.setBackground(d);