package com.example.to; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.widget.CompoundButton; import android.widget.ImageView; import android.widget.ToggleButton; public class MainActivity extends AppCompatActivity implements OnCheckedChangeListener{ /** * 初始化 * */ private ImageView ima; private ToggleButton tb; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); tb = (ToggleButton) findViewById(R.id.toggleButton); ima = (ImageView) findViewById(R.id.imageView; tb.setOnCheckedChangeListener(this); } @Override public void OnCheckedChanged(CompoundButton buttonView, boolean isChecked){ ima.setBackground(isChecked?R.drawable.OFF:R.drawable.ON); } }
OnCheckedChangeListener
OnCheckedChangeListener
有问题,一直报错。
zzZerOrz
qq_匡璐_0
totosspace