Created
September 23, 2017 01:54
-
-
Save ionixjunior/78c27167969ee3bbbc7e8153f799f042 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
namespace Droid | |
{ | |
public class MainActivity : FormsAppCompatActivity | |
{ | |
private static string _newTheme; | |
private static bool _canChangeTheme = false; | |
protected override void OnCreate(Bundle bundle) | |
{ | |
if (_canChangeTheme) | |
{ | |
if (_newTheme == "THEME-1") | |
{ | |
SetTheme(Resource.Style.ThemeOne); | |
} | |
if (_newTheme == "THEME-2") | |
{ | |
SetTheme(Resource.Style.ThemeTwo); | |
} | |
_canChangeTheme = false; | |
} | |
base.OnCreate(bundle); | |
... | |
} | |
// Vc chama este método quando necessitar mudar o tema | |
// Você pode preferir informar o tema como um Enum, fica melhor ali nas linhas acima para conferir | |
private void ChangeTheme(string theme) | |
{ | |
_newTheme = theme; | |
_canChangeTheme = true; | |
// recreate vai reiniciar a activity | |
Recreate(); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Droid/Resources/value/style.xml | |
<?xml version="1.0" encoding="UTF-8"?> | |
<resources> | |
<style name="MyTheme" parent="MyTheme.Base"> | |
</style> | |
<style name="ThemeOne" parent="MyTheme.Base"> | |
... definições tema 1 | |
</style> | |
<style name="ThemeTwo" parent="MyTheme.Base"> | |
... definições tema 2 | |
</style> | |
</resources> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment