onCheckedChanged()方法对Swtich控件没有影响

时间:2016-03-02 13:55:17

标签: android

$_SERVER["HTTP_REFERER"];

1 个答案:

答案 0 :(得分:0)

为我工作

vkSwitch = (SwitchCompat) view.findViewById(R.id.vkSwitch);

vkSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (!isChecked) {
                //do something
            }
            if (isChecked) {
               //do something
        }
    });

<android.support.v7.widget.SwitchCompat
                    android:id="@+id/fbSwitch"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_vertical"
                    android:textOff="OFF"
                    android:textOn="ON"
                    android:thumb="@drawable/customswitchselector"
                    android:track="@drawable/custom_track" />