我希望给用户提供选择应用程序颜色主题的机会。例如,我将实现一个黑色皮肤,其中包含不同色调的黑色颜色,以及一个白色皮肤,其中包含不同色调的白色颜色。
那么,最好的方法是什么?
例如,我知道在Android中有一个colors.xml文件,应该包含应用程序的颜色。是否有一种方法可以拥有两个颜色文件或类似的东西,并根据用户选择使用其中一个?也许是styles.xml文件?
请告诉我您认为哪种方法是最好的。
谢谢
我的布局:
那么,最好的方法是什么?
例如,我知道在Android中有一个colors.xml文件,应该包含应用程序的颜色。是否有一种方法可以拥有两个颜色文件或类似的东西,并根据用户选择使用其中一个?也许是styles.xml文件?
请告诉我您认为哪种方法是最好的。
谢谢
我的布局:
<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>
我的styles.xml文件:
<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>
SharedPreferences
中的颜色值以编程方式更改Statusbar
颜色、Toolbar
颜色、Fab颜色和任何其他颜色。如果您想要,我可以给您我的代码。但如果您想要检查一些东西,我建议您查看这个链接:android-change-app-theme-runtime。 - Yasin Kaçmaz