S
S
sfilmak2015-06-21 16:37:42
JavaScript
sfilmak, 2015-06-21 16:37:42

How to implement dynamic theme change (Android)?

Hello!
I found instructions on how to implement theme switching in Android applications, but for some reason it doesn’t work out for me. What could be?
Instruction: blabadi.blogspot.com/2015/01/android-multiple-them...
My code:

import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;


public class MainActivity extends ActionBarActivity {

    private final static String SELECTED_THEME= "THEME";

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        switch (item.getItemId()) {
            case R.id.theme:   if (SELECTED_THEME.equals("LIGHT")) {
                setTheme(R.style.AppTheme_Light);
                    return true;
        }
            }
        return super.onOptionsItemSelected(item);
    }
}

Thank you very much in advance!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Ruslan Yudin, 2015-06-21
@sfilmak

Why don't you have a break after the case block? And remove return true.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question