0

我的 android 设备中有一个用于 chromecast 的 MediaRouterButton。现在我想以编程方式启用/禁用它的点击,所以我有这样的代码行:

mediaButton.setClickable( false ).

但它并没有禁用它的点击,chromecast 对话框仍然出现。

我尝试检查它的源代码,它覆盖了 performClick() 方法,但是在我为此方法设置断点并调试后,我发现堆栈中除了这个 performClick() 之外没有任何方法。

谁能告诉我为什么会这样?

4

1 回答 1

0

最后我有一个工作......

只需覆盖 MediaRouteButton,覆盖其 performClick() 方法,插入您想要执行的逻辑。

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;
        }
    }
}
于 2016-01-07T03:51:04.200 回答