Android ImageButton - determine what resource is currently set

前端 未结 4 2079
Happy的楠姐
Happy的楠姐 2020-12-19 02:07

Is there a way I can find what resource a particular ImageButton is set to, at any given time?

For eg: I have an ImageButton that I set to R.drawable.btn_on

4条回答
  •  萌比男神i
    2020-12-19 02:28

    The documentation on android docs is incorrect. Here it states that pickDropPoint.getDrawableState()[android.R.attr.state_pressed] returns true or false, but instead it returns 1 or 0, an **int**.

    I had to do the following to get it working

                
    

    The drawable xml for pressed feel

    
    
    
    
        
        
        
    
    
    

    In code, you dont need the for loop as suggested by @slup

    whichPoint = (pickDropPoint.getDrawableState()[android.R.attr.state_pressed] > 1 ? PICKUP : DROP);
    

提交回复
热议问题