【发布时间】:2015-09-10 04:04:56
【问题描述】:
我的应用程序中有一个 TextView,并且想要更改相同 TextView 的背景颜色。当我第一次单击它时,它会是红色,第二次单击它会是绿色,第三次单击它会是蓝色背景有问题。
textType = (TextView)findViewById(R.id.textRNG);
textType.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v)
{
Drawable d = textType.getBackground();
Log.e("textType "," click !!! ");
if(d.getConstantState() == getResources().getDrawable(R.drawable.red_circle_shape).getConstantState())
{
textType.setBackgroundResource(R.drawable.green_circle_shape);
}
if(d.getConstantState() == getResources().getDrawable(R.drawable.green_circle_shape).getConstantState())
{
textType.setBackgroundResource(R.drawable.blue_circle_shape);
}
if(d.getConstantState() == getResources().getDrawable(R.drawable.blue_circle_shape).getConstantState())
{
textType.setBackgroundResource(R.drawable.red_circle_shape);
}
}
});
此鳕鱼无法正常工作。感谢适当。
【问题讨论】:
-
引入一个计数变量并在每次点击时增加它。然后根据计数值改变颜色
-
感谢所有代码都在工作。
标签: android