伙计们,我希望用户在用户选择时更改我的应用程序中所有活动的背景图像。我可以从更改图像的位置更改背景图像,Activity
但如果我尝试更改其他图像Activity
,我会得到一个NullPointerException
!是的,我已经检查了其他活动的 id Layout
!这是代码。
public class setting extends Activity {
TextView tv;
CheckBox cbS, theme1, theme2;
RelativeLayout rel;
OnClickListener checkBoxListener;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.setting);
cbS = (CheckBox) findViewById(R.id.cb);
theme1 = (CheckBox) findViewById(R.id.theme1);
theme2 = (CheckBox) findViewById(R.id.theme2);
// cbW=(CheckBox)findViewById(R.id.cbWordPress);
checkBoxListener = new OnClickListener() {
public void onClick(View v) {
if (cbS.isChecked()) {
// anything
}
if (theme2.isChecked()) {
RelativeLayout rel = (RelativeLayout) findViewById(R.id.rel);
Resources res = getResources();
Drawable drawable = res.getDrawable(R.drawable.back_image1);
rel.setBackgroundDrawable(drawable);
// findViewById(R.id.rel).setBackgroundResource(R.drawable.back_image1);
}
}
};
cbS.setOnClickListener(checkBoxListener);
theme2.setOnClickListener(checkBoxListener);
// cbW.setOnClickListener(checkBoxListener);
}
}