Android 将不同样式应用于应用程序

Android 将不同样式应用于应用程序,android,android-layout,android-theme,Android,Android Layout,Android Theme,我想创建一个android应用程序,用户可以在其中设置自定义主题,比如蓝色和红色。我已经创建了2个活动,用户可以从活动-1中选择颜色。但有可能以编程方式更改应用程序主题吗 我的风格是: <!-- Base application theme. --> <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"> <!-- Customize your theme here. -->

我想创建一个android应用程序,用户可以在其中设置自定义主题,比如蓝色和红色。我已经创建了2个
活动
,用户可以从
活动-1
中选择颜色。但有可能以编程方式更改应用程序主题吗

我的风格是:

 <!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/color_primary</item>
    <item name="colorPrimaryDark">@color/color_primary_dark</item>
    <item name="colorAccent">@color/accent_color</item>
</style>

<style name="RedTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/color_red</item>
    <item name="colorPrimaryDark">@color/color_red</item>
    <item name="colorAccent">@color/color_red</item>
</style>

@彩色/彩色原色
@颜色/原色\u深色
@颜色/强调色
@颜色/颜色/红色
@颜色/颜色/红色
@颜色/颜色/红色
我的工具栏

<android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:background="@color/color_primary"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize">
    </android.support.v7.widget.Toolbar>

我尝试使用
setTheme(R.style.RedTheme)
,但它并没有改变工具栏的颜色

请推荐我


谢谢。

如果无法创建活动,请使用此选项:

if (...) {
    getApplication().setTheme(R.style.BlackTheme);
} else {
    getApplication().setTheme(R.style.LightTheme);
}

它不会更改工具栏的颜色在清单中更改样式主题,但当用户选择所需主题时,如何在清单中更改它?在super.onCreate(savedInstanceState)之后和setContentView(…)之前设置主题在您的活动中,但我想将其设置为用户的愿望,即在按钮上单击按钮单击按钮单击可能是您需要通过销毁以前的实例来重新创建活动可能是,您的按钮单击时间是相同的活动还是不同的活动