Switch vs toggle

空扰寡人 提交于 2019-12-08 16:03:16

问题


I'm trying to decide whether to use a switch or toggle for setting an alarm I'm my android application. On fairly new to android and don't know or quite understand all the ins and outs of the frame work. What would be the disadvantages of choosing to trigger the alarm with a switch over a toggle, or vice versa? Is there a slide toggle available in android framework?


回答1:


The first thing you need to keep in mind is since which API do you want to compile your app?

Toggle Buttons are available since API 1 and Switches are only available since API 14.

Besides that is just a simple decision, which one is the best option for user interface/design In my opinion Switches give a clear indication of what is currently selected.

Is there a slide toggle available in android framework?

Yes a switch can work as a slide toggle.

The code is very simple, you can basically use the same thought for these two buttons.

Here is an example of a Switch Button

btnSwitch = (Switch) findViewById(R.id.switch_1);

btnSwitch.setOnCheckedChangeListener(new OnCheckedChangeListener() {
    @Override
    public void onCheckedChanged(CompoundButton buttonView,boolean isChecked) {
        if (isChecked) {
            Log.i("Switch", "ON");
        } else {
            Log.i("Switch", "OFF");
        }
    }
});

Here's an example of a toggle Button

btnToggle = (ToggleButton) findViewById(R.id.toggle_1);

btnToggle.setOnCheckedChangeListener(new OnCheckedChangeListener() {

    @Override
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
        if (isChecked) {
            Log.i("Toggle", "ON");
        } else {
            Log.i("Toggle", "OFF");
        }
    }
});


来源:https://stackoverflow.com/questions/21776356/switch-vs-toggle

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!