如何切换背景图像上单击按钮?单击、按钮、图像、背景

2023-09-04 05:20:41 作者:情定三生

我有这个code:

button1.setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        button1.setBackgroundResource(R.drawable.detailpressed);
        Chapter_sync.add(chapid);
    }

我所试图做的是切换所有调用以下clicklistener的方法。

What I am trying to do is toggle all the methods called in the following clicklistener.

例如:第一次,当我点击这个按钮的setBackgroundResource(R.drawable.detail pressed)被调用,并在接下来的点击相同的梅托德被称为具有不同的绘制。

Eg first time when I Click this button the setBackgroundResource(R.drawable.detailpressed) is called and on the next click same metod is called with different drawable.

喜欢的东西切换按钮。 有人擅长这plz帮助?

Something like toggle button. Someone good at this plz help?

推荐答案

你可以把一个变量

int i=0;

它会随着每一次点击。

it will increase with every click.

if(i%2==0)
   set one image
else 
   set another image