Skip to content

Instantly share code, notes, and snippets.

@ionixjunior
Created September 23, 2017 01:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ionixjunior/78c27167969ee3bbbc7e8153f799f042 to your computer and use it in GitHub Desktop.
Save ionixjunior/78c27167969ee3bbbc7e8153f799f042 to your computer and use it in GitHub Desktop.
...
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();
}
}
}
// 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