mercredi 31 janvier 2018

Changing app theme with checkbox (with java)

I'm adding a Dark Mode to my app and I've created a checkbox in the 3-dot menu (toolbar).

I want to make the app change the theme to Dark when the checkbox is checked, and revert it back to the Main theme when unchecked.

Here is my current code for onClick of Dark Mode Checkbox button:

    if (id == R.id.dark_mode) {

            switch (item.getItemId()) {
                case R.id.dark_mode:
                    if (item.isChecked()) {
// If item already checked then unchecked it
                        item.setChecked(false);
                    } else {
// If item is unchecked then checked it
                        item.setChecked(true);
                    }
                default:
                    return super.onOptionsItemSelected(item);
            }
        }

How can I do this using java?




Aucun commentaire:

Enregistrer un commentaire