更改Android的布局的背景颜色 [英] change background color of the layout in Android
本文介绍了更改Android的布局的背景颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个简单的Android应用程序,有3个按钮。当我点击1号按钮,我想改变布局的背景颜色(也就是现在的白...我想改变其他颜色,当我preSS的按钮)。我怎样才能做到这一点?
I have a simple Android application, with 3 buttons. When i click on the 1st button, i wanna change the background color of the layout (which is now white... i wanna change in other color, when i press the button). How can i do this?
在那个按钮,我有一个myClickHndler事件
On that button, i have a myClickHndler event
public void myClickHandler(View view) {
switch (view.getId()) {
case R.id.Button01:
text.setText("Button 1 was clicked");
break;
case R.id.Button03:
//text.setText("Button 3 was clicked");
.................... // ?
break;
}
}
谢谢!
推荐答案
举一个编号为您的的LinearLayout
是这样的:
Give an Id to your LinearLayout
like this:
<LinearLayout android:id="@+id/laidout"
...>
,然后从你的Java类说:
and then from your java class say:
...
case R.id.Button03:
//text.setText("Button 3 was clicked");
.................... // ?
mlayout= findViewById(R.id.laidout);
// set the color
mlayout.setBackgroundColor(Color.WHATEVER);
// you can use setBackgroundResource() and pass appropriate ID
// if you want a drawable bundled as resource in the background
mlayout.setBackgroundResource(R.drawable.background_img);
break;
...
:加code在评论请求的事
: added code for thing requested in comment
这篇关于更改Android的布局的背景颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文