Custom Checkable View which responds to Selector

前端 未结 6 473
生来不讨喜
生来不讨喜 2021-01-30 23:11

I have a group of FrameLayout which I want to be checkable/selectable,

That is, after a click I would like the FrameLayout to display as

6条回答
  •  有刺的猬
    2021-01-30 23:57

    Graeme's solution doesn't worked from me under Android 4.0.3 (and I suppose it won't work under 4.0 too). Instead you can change state_checked to state_activated:

    
    
        
        
    
    
    

    and use setActivated inside your setChecked:

    @Override
    public void setChecked(boolean checked) {
        mChecked = checked;
        setActivated(checked);
    }
    

    and that is all. Implementing onCreateDrawableState isn't required here.

提交回复
热议问题