I have some views inside my app which are using custom styles from my styles.xml file. For example:
<android.support.design.widget.NavigationView
android:id="@+id/navigation_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/drawer_header"
app:menu="@menu/drawer_menu"
style="@style/NavigationDrawerStyle"/>
With this style:
<style name="NavigationDrawerStyle">
<item name="android:background">@color/colorPrimaryDark</item>
</style>
I want to give the user the possibility to switch the style of some custom views of the app dynamically when the user presses a button of the screen. I know that if you call Activity.setTheme() before onCreate() method, you can change the theme of the app dynamically, but in this case, normal Views (for example, NavigationView), do not have setTheme or setStyle methods, so it is does not appear possible to change their style dynamically.
I have declared this style in my styles.xml file:
<style name="NavigationDrawerStyle.Grey">
<!--<item name="android:background">@color/colorPrimaryDark</item>-->
</style>
So, the perfect (but not possible) way to achieve this would have been something like this:
navigationView.setTheme(R.style.NavigationDraweStyle_Grey);
navigationView.setStyle(R.style.NavigationDraweStyle_Grey);
But as these methods do not exist... can't be achieved that way. Any help with this will be grated, I'm completely stuck with this.
Thank you