Search code examples
androidandroid-viewchromecastandroid-touch-event

setClickable() to false wont work on Android ChromeCast's MediaRouterButton


I have a MediaRouterButton for chromecast in my android device. Now i want to programmatically enable/disable its click, so I have such line of code:

mediaButton.setClickable( false ).

But it doesnt disable its click , the chromecast dialog still show up.

I try checking the source code for it, it overrides the performClick() method, but after I set a break point to this method and debug, i find no methods in the stack other than this performClick().

Can anyone tell me why this is happening?


Solution

  • Finally i have a work around....

    Just override the MediaRouteButton, override its performClick() method, insert the logic you wanna do.

    public class CustomizedChromesCastButton extends MediaRouteButton {
        private boolean enable = true;
        public CustomizedChromesCastButton( Context context ){
            super( context );
        }
        public CustomizedChromesCastButton(Context context, AttributeSet attrs){
            super( context, attrs );
        }
        public CustomizedChromesCastButton(Context context, AttributeSet attrs, int defStyleAttr){
            super( context, attrs, defStyleAttr );
        }
    
        public void setCastEnable( boolean enable ){
            this.enable = enable;
        }
    
        public boolean performClick(){
            if( enable ){
                return super.performClick();
            }
            else {
                return false;
            }
        }
    }