Android 当我点击一个Button后,当前的Activity背景改变(颜色或者图片),应该怎么写
2个回答
展开全部
public class MainActivity extends Activity {
RelativeLayout ly;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button btn=(Button)findViewById(R.id.btn);
ly=(RelativeLayout)findViewById(R.id.main);
btn.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
ly.setBackgroundResource(R.drawable.p1);
}
});
}
RelativeLayout ly;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button btn=(Button)findViewById(R.id.btn);
ly=(RelativeLayout)findViewById(R.id.main);
btn.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
ly.setBackgroundResource(R.drawable.p1);
}
});
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询