Changing background color in Android SDK by clicking a button does not work
Posted
by
DavidNg
on Stack Overflow
See other posts from Stack Overflow
or by DavidNg
Published on 2012-06-30T02:52:54Z
Indexed on
2012/06/30
3:15 UTC
Read the original article
Hit count: 182
I have a simple program which is able to change the background color after clicking a button, but it does not work
public class ChangeBackgroundActivity extends Activity {
/** Called when the activity is first created. */
Button blueButton;
LinearLayout myLO;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
myLO=(LinearLayout)findViewById(R.layout.main);
blueButton=(Button)findViewById(R.id.button1);
blueButton.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
// TODO Auto-generated method stub
myLO.setBackgroundColor(0x0000FF); //blue color code #0000FF
}
});
}
}
© Stack Overflow or respective owner