How to save the state of the toogleButton on/off selection?

前端 未结 3 1831
借酒劲吻你
借酒劲吻你 2020-12-16 08:24

Hello i have implemented the application based on the toggleButton selection. but while i close that application and then reopen it, it will get in to its default selection

3条回答
  •  感动是毒
    2020-12-16 08:39

    The best way, you can set tgbutton same

    screen main

    Intent intent = new Intent(this, Something.class);
    intent.putExtra(BOOLEAN_VALUE, Boolean.valueOf((tvConfigBoolean.getText().toString())));
                startActivity(intent);
    

    screen something

    Bundle bundle = getIntent().getExtras();
    tbtConfigBoolean.setChecked((bundle
                        .getBoolean(MainActivity.BOOLEAN_VALUE)));
    

    and save state

    editor.putBoolean("BooleanKey", tbtConfigBoolean.isChecked());
            editor.commit();
    

    good luck

提交回复
热议问题