I want to give the user the opportunity to select which color skin they'll have in my app. For example, I would implement a black skin with black colours with different tonalities and also a white skin with with tonalities.
What would be the best approach to achieve this?
For example I know that there is a colors.xml file in Android that should contain the colours of your app. Would be a way to have two colors files or something and to use one or other depending of user selection? Maybe a styles.xml file?
My layout:
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- The main content view -->
<RelativeLayout
android:id="@+id/main_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.view.ViewPager
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.view.PagerTitleStrip
android:id="@+id/pager_title_strip"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:paddingTop="4dp"
android:paddingBottom="4dp"
style="@style/CustomPagerTitleStrip"/>
</android.support.v4.view.ViewPager>
</RelativeLayout>
<!-- The navigation drawer -->
<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"/>
</android.support.v4.widget.DrawerLayout>
My styles.xml file:
<resources>
<style name="AppTheme" parent="Theme.AppCompat">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="actionBarTheme">@style/CustomActionBar</item>
<item name="android:textColor">@color/colorFontMenus</item>
<item name="itemTextColor">@color/colorFontMenus</item>
<item name="itemIconTint">@color/colorFontMenus</item>
</style>
<style name="CustomActionBar">
<!-- title text color -->
<item name="android:textColorPrimary">@color/colorFontMenus</item>
<!-- subtitle text color -->
<item name="android:textColorSecondary">?android:textColorPrimary</item>
<!-- action menu item text color -->
<item name="actionMenuTextColor">?android:textColorPrimary</item>
<!-- action menu item icon color - only applies to appcompat-v7 icons :( -->
<item name="colorControlNormal">?android:textColorPrimary</item>
</style>
<style name="CustomPagerTitleStrip">
<item name="android:background">@color/mainColorWithAlpha</item>
</style>
<style name="CustomTextView">
<item name="android:textColor">@color/colorFontContent</item>
</style>
<style name="CustomScrollBar">
<item name="android:scrollbarThumbVertical">@drawable/scrollbar_green</item>
</style>
<style name="CustomDrawerHeader">
<item name="android:background">@drawable/drawer_header_background_green</item>
</style>
<style name="NavigationDrawerStyle">
<item name="android:background">@color/colorPrimaryDark</item>
</style>
</resources>
Statusbar
color,Toolbar
color , Fab color, and any other color whatever i want programmatically based on a color value inSharedPreferences
. If you want i can give you my code. But if you want to check sth i can suggest you look this : android-change-app-theme-runtime – Stylus