如何切换背景图像上单击按钮? [英] How to toggle background image on button click?

查看:116
本文介绍了如何切换背景图像上单击按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个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

这篇关于如何切换背景图像上单击按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆