在Android系统中,是否有一种设置按钮的方法,使我每次运行该程序时,该按钮具有不同的属性?
即每次运行程序时都有不同颜色背景的按钮
发布于 2014-02-17 17:58:02
在你找到按钮的活动中
Button btn = findViewById(R.id.myButtonId);把它的背景色设置成这样
int color = // generate some random color
btn.setBackgroundColor(color);发布于 2014-02-17 18:07:04
您可以使用随机()来将背景色设置为按钮。
例如:
int[] color={Color.RED,Color.BLACK,Color.GREEN};
onCreate()
{
Button b=(Button)findViewById(R.id.button1);
Random random=new Random();
b.setBackgroundColor(color[random.nextInt(3)]);
}https://stackoverflow.com/questions/21836041
复制相似问题