开发者

In Android, how to read the current button background image?

I am trying to find a way to read a button’s background image name (I have three different possible images for each button in the button state xml file) so that every time a user click on the button I can put that image name value in if statement to see if I need to change the button image to the next image or not (of the 3 images)

I tried this

button1.getBackground()

Then I used the toast to show the valie of that using this:

Toast.makeText(TreActivity.this, String.valueOf(button1.getBackground()) , Toast.LENGTH_SHORT).开发者_如何学Goshow();

I was thinking it will give me one of my 3 button state images but instead it gave me this: android.graphics.drawable.BitmapDrawable@44f01d58

So how can I get the current background drawable image currently assigned to the button?

Thanks in advance for everyone's help!


i think this will working for u my my app i used this getting image from image view.

img_View11.setOnClickListener(new View.OnClickListener()  {            
    public void onClick(View v)  {           
        ImageView iv = (ImageView)v;                 
        Drawable d = iv.getDrawable();                                   
        }                
       }
    }); 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜