简体   繁体   中英

Android App theme is not changing when I press the system back button

I know there are similar questions asked but I couldn't find a proper answer.

Current Status of app

Right now I have implemented the two themes AMOLED / Day / System Default and everything is working fine. To switch the theme of the app I am using the following command

setTheme(R.style.Theme_RandomApp_Day);

Problem

When I am switching the theme by the above command [settings.java], the theme changes normally and when I press the back arrow on the toolbar of the app [In app toolbar, not system back button], parent activity launches [MainActivity.java] and the theme of this activity is the one that I have set in settings activity. Till now the functionality is what is expected.

But when I perform the same task [changing the theme in settings.java] the theme in settings.java changes but this time with the smartphones inbuilt back button when pressed the theme in the MainActivity.java does not change .

To solve the problem as drjansari I used the following code

@Override
    public void onBackPressed() {
        super.onBackPressed();
        finish();
        startActivity(new Intent(settings.this, MainActivity.class));
    }

And It worked but now I have another problem XD

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM