当前位置: 代码迷 >> 综合 >> android studio togglebutton
  详细解决方案

android studio togglebutton

热度:5   发布时间:2024-01-14 12:27:28.0

这个和switch太相似了,用toast小试牛刀:

public class MainActivity extends AppCompatActivity {ToggleButton toggleButton;@Override
    protected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);toggleButton=(ToggleButton)findViewById(R.id.toggleButton);toggleButton.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {@Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {if (b){Toast.makeText(getApplicationContext(),"on",Toast.LENGTH_SHORT).show();}else {Toast.makeText(getApplicationContext(),"off",Toast.LENGTH_SHORT).show();}}});}
}

  相关解决方案